Jump to content

please help, im a little stuck (and new to php)


marsdenc

Recommended Posts

i have the below code but i cant figure out how it works to track an ip when there are many ip's on the same network using it as it only gives the main ip and does not relate to individual users.

 

can any one help?

 

<?php

 

extract($_POST, EXTR_PREFIX_SAME, "post_");

 

putenv("TZ=london");

 

$filename = 'statistics.txt';

 

$somecontent = date('[d/m/Y:H:i:s T O]')." ".$_SERVER['REMOTE_ADDR'].": ".$title.": ".$state."\n";

 

if (is_writable($filename)) {

 

if (!$handle = fopen($filename, 'a')) {

echo "Cannot open file ($filename)";

exit;

}

 

 

if (fwrite($handle, $somecontent) === FALSE) {

echo "Cannot write to file ($filename)";

exit;

}

 

echo "Success, wrote ($somecontent) to IP log ($filename)";

 

fclose($handle);

 

} else {

echo "The file $filename is not writable";

}

 

?>

A page is requested by a single user (from a single ip) and therefore each call is just a single instance. Hope this make things a little clearer? Unless their logged in or you can correlate from a lookup ip table then no you don't know who the user is, other than being identified by an ip (or other $_SERVER info), all of which can be falsified! Fun isn't it!

How do you mean track?

Have a look at sessions, e.g. set a session cookie...

 

This will be done a a per browser basis, for instance at times i'll use different browsers from same pc to test multi users from same ip. If you log the ip, browser details and session id then you'll start to have a bigger picture of what's going on!

If your new, then you know you have a lot of reading to do then!

First off you should always google for some tutorials, for instance you might find one here:

http://www.tizag.com/phpT/phpsessions.php

Another good thing to do is refer to the manual and search that e.g.

http://uk.php.net/session

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.