Archive for the 'PHP' Category

PHP Include Injection and Google Referral Hijack

So recently a friend of mine, had a client that had a very odd problem. His website was working fine when you go to it directly by typing in the domain name; however, if you searched for the site in Google and clicked the link for the site it would take you to a hijacked page.

So the page only appeared hijacked when the referral was coming from Google. The hijack could go unnoticed for months. You would either have to be googleing yourself or wait until a good samaritan sends you an email warning you of the problem. I must say this sort of attack is quite clever on the hijacker’s part. The hijacked page gets the original site’s page rank and Google visits while the site owner has absolutely no clue. Read more »

Random Password (String) Generator for PHP

Random string generators are something we programmers end up using quite a bit. Sometimes you want to generate a random file name, a random email verification link, a random password, random token, etc.. Here is the one that I have been using lately.

This password generator uses the Mersenne Twister algorithm to generate random digits. You can learn more about it at Wikipedia or on Makoto Matsumoto’s website. Read more »

Printing a Label for USPS with PHP

If you have been following the posts on USPS you should know how to calculate USPS shipping rates with PHP. Today we are going to use the same USPS API to print out a label. One of the advantages of this is that you get free tracking on all priority shipments when you create your own label. The other advantages is that you get to integrate automatic label generation with your website for customers or for your own shipping.

Start off by making a file called, USPSLabel.php and copy and paste the code below and save it.

Then Change the userName variable with your USPS username and change the rest of the variables to match your label. Read more »

Why I use the Zend Framework

Frameworks seem to be popping up all over the place for all sorts of languages. These frameworks all have one goal. They are looking to reduce development time. Time is money and when you are working on client’s sites frameworks can drastically reduce the development time. For this reason frameworks are not going away any time soon.

Why a framework?

 
If you haven’t tried a framework for web development do yourself a favor and just go try one. Adding skills to your skill set will help you in future projects. You may find yourself forced to work on a framework in the future so why not get a head start and learn one.

They say a good programmer is a lazy one. Why reinvent code? Why come up with custom code that other programmers will have to decipher when it comes maintenance time. Why not have code that is already well documented and widely known. Why not allow someone else to research the industry standard way of doing the mundane tasks while you focus on the real programming? Read more »

Validating an Email Address With Zend Framework

Email addresses are one of trickiest input types to validate because there are multiple ways emails can be written according to the RFC2822 specification. You could have me@gmail.com, or me+spam@gmail.com, or “mark@server”@marksanborn.net, common on Linux/BSD systems.

A lot of times people will use a regular expression like:

(\w+@[a-zA-Z_]+?\.[a-zA-Z]{2,6})

This regular expression would work for almost all email addresses but would fail for others. For example mark@gmail.co.uk would not match. Either would mark+spam@gmail.com. Which by the way is a very useful feature for email hosts that support it. Read more »

Validating Credit Card Numbers with Zend Framework

Ever wonder how websites can tell you made a mistake entering your credit card number before you even submit it? Like most identification numbers credit cards have checksum digits built into them. Just like barcodes.

If you ever look at a EAN-13 UPC barcode (on all retail products) you will notice there is a digit outside of the regular set on the right. If any digit is out of order or mistyped you can tell that the barcode is wrong based on this checksum. It also allows barcode readers the ability to “guess” what the barcode if part of the barcode got riped or damaged. This is also how PAR files can repair corrupt damaged or even missing files. Read more »

Setting Up a Sandbox Server with SVN

SVN is one of those things that you love once you know what and how it works. SVN is a version control system used by almost all major open source projects and is an absolute dream to work with. If you have ever worked with a team of developers you probably have had the experience of having your code accidentally written over or deleted.

With SVN you have version control where you can revert changes, kinda like Wikipedia. It also keeps track of which files were actually modified and gives you an option to describe to other developers what changes were made. No more unfortunate mishaps. :)

What is great about SVN is that the code can be checked out to any server at any time with the latest code. I use SVN to make a “sandbox” server. A server that I can play around in without worrying about deleting code or messing something up. When I am happy with my changes I can type one command and the two servers are synced with the newest changes. If for some reason it doesn’t work out I can revert back to the old way in one easy command. Read more »

New UPS PHP Project at Google Code

Out of popularity I have decided to take UPS modules written in PHP found in my article, Calculating UPS Shipping Rate with PHP, over to the next level. I am rewriting all the code in object oriented PHP and publishing the code on Google Code under GNU General Public License v3 to ease implementation.

I am also going to be writing official documentation in the Google Code wiki pages.

This doesn’t mean that I am going to stop writing articles about UPS here on this blog. I will still add more detailed articles about the code and provide tutorials for implementation. The project at Google code is just so the project can grow and provide support, bug tracking, svn access, and official documentation. Read more »

Next Page »