Beginner PHP Tricks To Customize Your Site
As a server-side scripting language, PHP can be used to optimize each user’s experience on your site. For this reason, it is popular with many popular Web 2.0 sites such as Wikipedia, WordPress and Facebook. These sites all utilize PHP to customize sites to the individual interests of users.
In today’s web environment, the more information developers are able to glean about their site users, the better they are able to customize the sites they design. The Web 2.0 era brings on the necessity for developers to know more about their visitors than ever. PHP allows developers to adjust site content into user-specific content and increase user satisfaction.
While there are many tutorials out there on using PHP, here we are going to outline 6 PHP steps that are easily incorporated into your site without you having to gain an in-depth knowledge of PHP.
- 1. Keeping Content Up-To-Date
Up-to-date content is important even if it is something as basic as today’s date. By using PHP, you can give users current information relevant to their location each time. PHP is able to make each visit for the user as current as possible.
The coding for a PHP command to show current date is:
$date = Date(“F d, Y”);
echo “The current date is ” . $date;
- 2. Displaying Site Load Time
In the past, load times were not that important, but today visitors simply are not willing to hang around for a site with a long load time because there are too many sites out there that do load quickly. Here is a code you can insert into the and tags to find out if your site is loading too slow so you can take steps to fix it:
$starttime = microtime();
$startarray = explode(” “, $starttime);
$starttime = $startarray[1] + $startarray[0];
Insert this code into the tag of your site:
$endtime = microtime();
$endarray = explode(” “, $endtime);
$endtime = $endarray[1] + $endarray[0];
$totaltime = $endtime – $starttime;
$totaltime = round($totaltime,10);
echo “Seconds To Load: “;
printf (“%f\n”, $totaltime);
- 3. Customized Site Design
PHP will let you customize your site to show different themes each day, for example, a party theme on Fridays. Alternately, PHP allows you to change the entire look of your site to give it a new look for each new and returning user, keeping it fresh and fun. To do this, put this code inside the and tags of your site:
$day = date(“w”);
$color = array(“white”, “orange”, “purple”, “pink”, “red”, “blue”, “green”);
If you want to change colors on specific site elements daily, insert this tag into the element:
print(“style=\”color:$color[$day];\”");
- 4. Comments and Customization
It’s been proven that people are most interested in sites that reflect their interests. Creating a site that is customized for each user gives users a feeling of importance. Web 2.0 is focused on the individual user with content, interactivity and unique personalization. By using PHP to ask users to enter information about themselves, the limits on how customized your site will be is unlimited.
The easiest way to do this is by creating forms. This is a more in-depth use of PHP so a good tutorial for this is located at PHP Forms and User Input Tutorial by w3schools.
- 5. Adding Daily Inspirations
One interesting feature for users to your site is to add daily quotations. These can be adjusted to display a daily quotation or thought of the day, or a random display that changes with each visit to the site. To add this feature, insert the following code replacing “Quote 1, Quote 2″ etc. with the selected quote:
$quote = array(
1 => “Quote 1″,
2 => “Quote 2″,
3 => “Quote 3″,
4 => “Quote 4″,
5 => “Quote 5″,
);
srand ((double) microtime() * 1000000);
$randnum = rand(1,5);
echo”$quote[$randnum]“;
- 6. Displaying Referrals
PHP can also show how each user was directed to your site. Since users will know how they got to your site, it may be helpful to combine this script with a unique page for users directed from a particular location. This script should be inserted at the top of the page you’re building. The coding given as an example, sends all visitors who were sent to your site through Facebook to one specific page, redirecting users directed from other sources to another page.
if (strlen(strstr($_SERVER["HTTP_REFERER"],”twitter”))>0) {
header (‘Location: http://’ . $_SERVER['HTTP_HOST'] . ‘/from_facebook.html’);
} else {
header (‘Location: http://’ . $_SERVER['HTTP_HOST'] . ‘/not_from_facebook.html’);
}
Conclusion
By incorporating PHP into your site, you can gather as much dynamic information about users as possible. This comes in as a great tool for feedback and making content more user specific. The server interacting with the user information makes the a user feel recognized, which in turn keeps them coming back.
Mike A. is a PHP web developer for a webhosting company in Los Angeles. Follow him on Twitter @WHHG_InMotion.
Category: Tutorials


