PHP ip logger
#1
Posted 08 May 2006 - 01:07 AM
Mainly, cause I want to see who is checking my myspace page (Yea, i know.)
I don't need it to change the image every time (Image rotator), or depending on the ip (Like vipersig)
but being able to use my image rotator php in it would be nice.
But what I would like aside from the ip logging, would be if I can log which myspace user is visiting my page. All I know is each page gets a token added to the end of the address when I'm logged in, so is that token id usable to me to identify someone to a myspace account?
Er, and I want to run the code on my web host, not use one of those other services.
#2
Posted 08 May 2006 - 01:34 AM
<img src="http://yoursite.com/...m/myimage.php">
then we assume you have a jpeg called "image.jpg" on yoursite.com
mimagge.php would look like this
<?php
header('Content-type: image/jpeg');
readfile('image.jpg');
$filename = "logged.txt";
$somecontent = "Connection from:".$_SERVER['REMOTE_ADDR']." at ".date("r",time())."\n";
if ($handle = fopen($filename, 'a')) {
fwrite($handle, $somecontent)
fclose($handle);
}
?>
Edited by replax, 08 May 2006 - 10:45 PM.
#3
Posted 08 May 2006 - 08:45 AM
#4
Posted 08 May 2006 - 10:17 PM
Edit: When I try uploading replax's script to my server it says there's an error. Ideas?
Edited by Fish, 08 May 2006 - 10:59 PM.
#5
Posted 08 May 2006 - 10:47 PM
#6
Posted 09 May 2006 - 01:25 AM
But keep in mind my caveots
It assumes you have an image called. image.jpg in the same directory as the script. You can change that to suit your needs.
The user the webserver is running as (and therefor the user php is running as) needs write access to the file logged.txt. You may have to create it with ftp or a ssh shell and chmod 777 it to make it writable.
What is is the error it is spitting at you?
#7
Posted 09 May 2006 - 06:52 PM
#8
Posted 09 May 2006 - 10:31 PM
here:
<?php
header('Content-type: image/jpeg');
readfile('image.jpg');
$filename = "logged.txt";
$somecontent = "Connection from:".$_SERVER['REMOTE_ADDR']." at ".date("r",time())."\n";
if ($handle = fopen($filename, 'a')) {
fwrite($handle, $somecontent);
fclose($handle);
}
?>
#9
Posted 14 May 2006 - 09:38 PM
#10
Posted 14 May 2006 - 10:10 PM
Now, do I need to name the script *.php to run correctly? Or can I name it .j or .jpg?
It has to be .php unless your php settings are set to parse jpg, i dont think they are by default.
So long as the header information is sent out defining the file type, you shouldnt run into any problems referencing it like a normal image.
#11
Posted 15 May 2006 - 09:02 AM
incase anyone didn't know; PFI started a thread about this code in the programming/code section. There I go into it in more depth and describe exactly how it works.
Other Thread
#12
Posted 18 May 2006 - 12:36 AM
Since I couldn't get the script working, and a change from catalog.com to webhero.com forced me to change my password on the account, I saw that it has webstats option, which i can ftp into and copy all the individal day's logs. Now i get a copy of every ip that loads an image on my myspace hosted on my website. Sweet
#13
Posted 18 May 2006 - 10:02 AM
if you have hosting that supports .htaccess then you can get around this.
rename the script to a .jpg and add this into a .htaccess
AddType application/x-httpd-php .jpg
This comes with the caveot that all other .jpg's in that directory will no longer work unless you make php scripts like this for each. So the full url looks like a .jpg, but it is a php script that outputs a jpeg image. If you don't want jpegs to be associated with php in this way (so other jpgs in the directory will work normally) then you can change it to .gif or .png. The last name doesn't really matter as long as the script's name ends with what you have in the AddType line. So to get around blocks like that you can make up your own extension or use one of the common graphics ones.
BinRev is hosted by the great people at Lunarpages!











