Dan Williamson
18-12-2005, 11:20 PM
Hey guys.
Heres my 4th PHP tutorial just rate it and tell me what you think.
We'll be going over user information and statistics.
We'll be going through loads.
Users IP.
Too show the users IP adress
<?php echo $_SERVER["REMOTE_ADDR"]; ?>
Very simple, one line of code just place it in your table or wherever you want the IP adress to show.
An advanced and better way of getting someones IP adress
<?php
if(getenv(HTTP_CLIENT_IP)) {
$host = getenv(HTTP_CLIENT_IP);
}
elseif(getenv(HTTP_X_FORWARDED_FOR)) {
$host = getenv(HTTP_X_FORWARDED_FOR);
}
else {
$host = $REMOTE_ADDR;
}
?>
Browser Info
This is another easy one line code.
<?php echo $_SERVER["HTTP_USER_AGENT"]; ?>
Very basic and easy too use.
Referer
Heres how too see what site they came from.
<?php echo $_SERVER["HTTP_REFERER"]; ?>
Hit Counter
Now there a lot of different hit counters out there.
We're going to be using one like i'm using on my site, one thats run off a text file.
Now lets create a blank .txt file called count.txt
Now heres the simple PHP code.
<?php
$fp = fopen("count.txt","r");
$count = fread ($fp, filesize
("count.txt"));
fclose($fp);
$count++;
$fp = fopen("count.txt","w");
fwrite($fp, $count);
fclose($fp);
echo "Hits : $count";
?>
Now you need to CHMOD the text file too 777 if you don't know how to do that then you shouldn't use this tutorial.
This is my 4th tutorial and they will all be used on my upcoming site opening 1st January 2006
- Dan
Heres my 4th PHP tutorial just rate it and tell me what you think.
We'll be going over user information and statistics.
We'll be going through loads.
Users IP.
Too show the users IP adress
<?php echo $_SERVER["REMOTE_ADDR"]; ?>
Very simple, one line of code just place it in your table or wherever you want the IP adress to show.
An advanced and better way of getting someones IP adress
<?php
if(getenv(HTTP_CLIENT_IP)) {
$host = getenv(HTTP_CLIENT_IP);
}
elseif(getenv(HTTP_X_FORWARDED_FOR)) {
$host = getenv(HTTP_X_FORWARDED_FOR);
}
else {
$host = $REMOTE_ADDR;
}
?>
Browser Info
This is another easy one line code.
<?php echo $_SERVER["HTTP_USER_AGENT"]; ?>
Very basic and easy too use.
Referer
Heres how too see what site they came from.
<?php echo $_SERVER["HTTP_REFERER"]; ?>
Hit Counter
Now there a lot of different hit counters out there.
We're going to be using one like i'm using on my site, one thats run off a text file.
Now lets create a blank .txt file called count.txt
Now heres the simple PHP code.
<?php
$fp = fopen("count.txt","r");
$count = fread ($fp, filesize
("count.txt"));
fclose($fp);
$count++;
$fp = fopen("count.txt","w");
fwrite($fp, $count);
fclose($fp);
echo "Hits : $count";
?>
Now you need to CHMOD the text file too 777 if you don't know how to do that then you shouldn't use this tutorial.
This is my 4th tutorial and they will all be used on my upcoming site opening 1st January 2006
- Dan