PHP


PHP can be used to write programs for websites. Server information is automatically stored in PHP variables.

Example: writing a log that keeps track of visitors to your web site.
<?php
$logfile= './log.txt';
$logdetails=  date("F j, Y, g:i a") . ': ' .$_SERVER['REMOTE_ADDR']." ".$_SERVER['HTTP_REFERER']."\r\n";
$fp = fopen($logfile, "a");
fwrite($fp, $logdetails);
fclose($fp);
?>
To call this script (let's call it example.php) put the following lines into your .htaccess file (and .shtml or .php postfixes):
RemoveHandler .html .htm
AddType .php .htm .htm
Example 2: generate user-specific webpage content.
E.g., your IP address is: 3.142.98.108
Using this code:
<?php
echo $_SERVER['REMOTE_ADDR'];
?>


Back to Resources