Link To Full Story: webhostinghelpguy.inmotionhosting.com
An article that details all the uses of PHP would be as long as the New York City phonebook, and about as exciting to read. And while we have tutorials on PHP planned for the future, we thought we’d start everyone off with six fun and easy PHP tricks you can try right now, no matter what your familiarity with the language is.
1. Referrals
This simple example shows the user how they got to your site.
$referer = $_SERVER['HTTP_REFERER']; echo "You reached this site via " . $referer;
See It In Action: You reached this site via http://www.dzone.com/links/rss/php_tricks_for_beginners.html
Since a user knowing how they got to your site isn’t particularly useful, you need to combine the above script with something, such as a unique page for users who come to your site from a particular location. For example, the script below would send visitors who found your site through Twitter to one page, while all others would be redirected to another. This script, just FYI, needs to go at the very top of the page you’re building.
if (strlen(strstr($_SERVER["HTTP_REFERER"],"twitter"))>0) {
header ('Location: http://' . $_SERVER['HTTP_HOST'] . '/from_twitter.html');
} else {
header ('Location: http://' . $_SERVER['HTTP_HOST'] . '/not_from_twitter.html');
}
Post a Comment