Handling Purchased File Downloads

Making it so your website can handle file downloads is very important now-a-days. Either it be when you are giving out your free CD or if you want to distribute your software. The above two are simple, you simply link to a public location where the file is accessible. But what if you want users to buy your software or music? Now it gets a little more interesting.

The first obvious solution is to find a service that handles this, such as iTunes or a software distributor. But if you want a system built into your own website, we can help you.

PHP Prevent Include Direct Access

It’s good practice to limit where your website visitors can go so they don’t get into trouble or cause problems with your site. Although, problems should occur when they directly access a file they are not supposed to, sometimes you can’t help it.

Below is a very simple way to prevent your users from directly accessing important system files for your website.

What you have to first do is identity a file that all pages use and include. Most sites now have a single “index.php” file which is used to parse the URL and then load the appropriate content. If that’s the case with your website, you will want to use index.php in this tutorial. If your website is using a more classic approach of having each webpage as a different file, you can use a file you include on every site such as “header.php”, but keep in mind that this file will not be protected like the others. Also note that this has to be the first file you include.

Setup PHP Development Web Server Quickly inside of Windows

Since PHP 5.4.0, the developers included one of the most amazing features to ever exist. A built in development web server. In the below steps or if you choose to, in the video, you will learn to setup and run your own development web server using only the PHP client. You don’t have to worry about setting up and configuration Nginx, Apache, IIS or various other server software to quickly test your website before publishing it.

PHP Dynamic Subdomains

Giving users a subdomain name is sometimes better when you want users to have their own piece of the website. For example, Tumblr, Blogger, WordPress all will give you a subdomain name. A subdomain is a prefix on the existing URL followed by a period. The most common sub domain you will see is “www”.

To give you users a subdomain is a little more difficult than just having the users profile as a directory on your site. You have to modify your web servers virtualhosts or host mapping, you also need to modify your DNS (sometimes).

PHP Calculate Time for Hashing Algorithms

Figuring out the time required for each hashing algorithm in PHP is a simple task of running a string through the hash() function and timing it with microtime(). I needed to do this for all of the available algorithms and sort them from fastest to slowest. Please keep in mind that if hashing for the purpose of passwords, don’t go by which hashing function is the fastest, security can take a few extra thousandths of a second. If you are wondering why this would ever be useful, when time is a really important factor, hashing using the proper algorithm is useful. Hashing is used for more than just passwords. Hashing is often used as “checksums” to verify files and their original source, checking for duplicate files when stored in a database, and more.