|

09-08-2011, 09:49 AM
First, you need to create a log table with the following code:
create table log (
num int(11) not null auto_increment,
ip not null varchar(20),
referer not null varchar(50),
primary key (num)
);
After creating the table, add the following code at the top of the page(s) in your site, for which you want to get
ip address and referer:
<?
$ip = $_SERVER['REMOTE_ADDR']; // user IP address
$referer = $_SERVER['HTTP_REFERER']; // URL link that the user visited or the URL they passed
// put here the script for database connection
if($referer) {
$query = "insert into log (ip, referer) values ('$ip', '$referer')";
mysql_query($query);
}
?>
EDIT:
You can get $referer when the user clicked the URL for your site, in the
previous page that the user was visiting.
Last edited by grace1004; 09-08-2011 at 04:49 PM.
|