...

View Full Version : PHP ? thing



CallumTennant
01-11-2012, 01:39 AM
Ok, first off I'm a bit of a noob when it comes to PHP.

What I am looking to do is find the IP address of my friend. I'm needing a code that when I send a specific link to my friend (example: http://example.com/index.php?specialcodetoidentify). I need it to write information to a file called ip-log.txt and it needs to have the time, date, IP and what URL the web page was viewed on.

So when I send the link with a random .php?codeofmychoise, the ?endthing has to be in the ip-log.txt. Does anyone have a code that is able to do all this?

Yes, I am a massive noob at PHP. Sorry!

mlseim
01-11-2012, 03:58 AM
IP addresses change ... as they are dynamic.
Not reliable, and your friend may have a different one each time he/she accesses your site.

Only an actual user login is accurate.

Sorry, there's really no way to determine who the person is without a unique login.

Alternative
01-11-2012, 09:51 AM
$_POST['REMOTE_ADDR'] holds the viewer's IP address in PHP. However like mlseim said, IP addresses are easily changed.

The PHP date object can get you the date when the page was accessed.

date = date("n-j-Y"); will give you the date in the format of mm-dd-yyyy into a string.

$_POST['HTTP_REFERER'] holds the page from where the user came from, but it cannot be really trusted because it is easily changeable.

_Aerospace_Eng_
01-11-2012, 03:00 PM
No $_POST['REMOTE_ADDR'] doesn't hold the IP, nor does $_POST['HTTP_REFERER'] hold the referer. It should be $_SERVER['REMOTE_ADDR'] and $_SERVER['HTTP_REFERER'].

CallumTennant
01-11-2012, 05:44 PM
This is the current code I'm using:

<?php
$ip = $_SERVER['REMOTE_ADDR'];
$dt = date("l dS \of F Y h:i:s A");
$file=fopen("ip_log.txt","a");
$data = $ip.' '.$dt."\n";
fwrite($file, $data);
fclose($file);
?>

All that gives me is the Time, Date, Month and the IP. How would I add
$_SERVER['HTTP_REFERER'] to it though?

Yes, I am just starting PHP.

Red_Rain
01-11-2012, 09:00 PM
This is the current code I'm using:

<?php
$ip = $_SERVER['REMOTE_ADDR'];
$dt = date("l dS \of F Y h:i:s A");
$file=fopen("ip_log.txt","a");
$data = $ip.' '.$dt."\n";
fwrite($file, $data);
fclose($file);
?>

All that gives me is the Time, Date, Month and the IP. How would I add
$_SERVER['HTTP_REFERER'] to it though?

Yes, I am just starting PHP.

You were able to write all that above but not figure how to echo the referer?? LOL i am really new to PHP too so dont take my word for it but i think that you could just say


$refer = $_SERVER['HTTP_REFERER']
........ $data = $ip.' '.$dt."\n" . $refer



Like i said, i do not KNOW but i think thats worth a shot. Good luck!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum