PHP means „PHP: Hypertext Preprocessor “, originally „personal Home Page Tools“ and is a popular program language to make dynamic websites. Rasmus Lerdorf was creator of the programming language. Examples of popular server-side PHP applications include phpBB, WordPress and MediaWiki. Nowadays, PHP is installed on the most webhosting servers.

1. Syntax


The most popular beginner Code is:

<?php
echo ‘Hello World!;
?>
 
A PHP code begins always with <?php and ends with also ?>.

You can insert comments in PHP exactly the same as in HTML. There are three possibilities to set comments.

First possibility:

**/*** PHP Statement ***/**


With this syntax block comments are commentated

Second possibility:
//PHP Statement

This is used for inline comments.

Third possibility:

###################
### PHP Statement ###
###################

This is used for inline comments, too.

2. A simple Counter-Script


<?php
 
 
$pfad = "";   /* Path to the file */
$counter = 6;  /* Counter Initial value */
$sperrzeit = 3600;     /* IP barrier in seconds */
$max = 999999999;  /* File after 1000 visitors clear up (number of visitors*2+1)*/
$grafikcounter = "yes"; /* yes/no (Text- or Grafikcounter) */
$extender = ".gif";  /* Image file format (only with Grafikcounter) */
$width = "57";  /* Width of the Grafik in pixels */
$height = "57";    /* Height of the diagrams in pixels */
$font = "arial";    /* Character type of the Textcounter */
$size = "18pt";    /* Character size of the Textcounter */
$color = "lime";   /* Color of the Textcounter */
$weight = "bold";  /* Writing strengthens of the Textcounter (bold or normal) */
 
 
 
$ip = getenv("REMOTE_ADDR");
//The IP of the visitor
 
$zeit = time();
//current time
 
$datum = date("Y-F-d-l - H:i:s");
//The Date Output format
 
$ip_exist = false;
 
if(!file_exists($pfad."counter.txt"))
{
$counter++;
$daten = array();
$daten[0] = $counter;
$daten[1] = $ip;
$daten[2] = $zeit;
$daten[3] = $datum;
$teile = implode("|", $daten);
$handle = @fopen($pfad."counter.txt", "a");
@fputs($handle, $teile);
@fclose($handle);
}
$read_handle = @fopen($pfad."counter.txt", "r+");
@flock($read_handle,LOCK_SH);
$daten = @fgets($read_handle);
@flock($read_handle,LOCK_UN);
@fclose($read_handle);
$teile = explode("|", $daten);
$anzahl = count($teile);
if($anzahl > $max)
{
for($n=1; $n<$anzahl; $n++)
{
unset ($teile[$n]);
}
$anzahl = 1;
}
for($n=1; $n<$anzahl; $n++)
{
if($teile[$n] == $ip)
{
$ip_exist = true;
if($zeit > $teile[$n+1]+$sperrzeit)
{
$ip_exist = false;
unset ($teile[$n]);
unset ($teile[$n+1]);
break;
}
}
}
if($read_handle == true)
{
if($ip_exist == false)
{
$teile[0]++;
$teile[] = $ip;
$teile[] = $zeit;
$teile[] = $datum;
$daten = implode("|", $teile);
$handle = @fopen($pfad."counter.txt", "w");
@flock($handle,LOCK_EX);
@fputs($handle,$daten);
@flock($handle,LOCK_UN);
@fclose($handle);
}
if($grafikcounter == "no")
{
echo "<span style='font-family: $font; font-size: $size; color: $color; font-weight: $weight;'>";
echo $teile[0];
echo "</span>";
}
elseif($grafikcounter == "yes")
{
$gcount = (string) $teile[0];
for($n=0; $n<strlen($gcount); $n++)
{
echo "<img src='$pfad".$gcount[$n]."$extender' width=$width height=$height border='0' alt=''>";
}
}
}
?>
 

3. Links


http://php.net/ - Official PHP website
http://www.php-resource.de/ - Good PHP Scripts, Html & Co Scripts, too.

www.cr-home.de – My Page
http://blog.cr-home.de/ - My Blog about all things (German)

Christopher Röhrl, student of RS Regenstauf