Jump to content


Photo
- - - - -

PHP ip logger


  • Please log in to reply
12 replies to this topic

#1 chaostic

chaostic

    rekcah-rebÜ

  • Members
  • 724 posts

Posted 08 May 2006 - 01:07 AM

I'm trying to find one of those php ip logger things that when i link a image in one page, logs the ip, maybe time/date, and reffering page (or page that holds the image).

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 replax

replax

    Hakker addict

  • Members
  • 505 posts

Posted 08 May 2006 - 01:34 AM

you would add an image so the html looks like

<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 Irongeek

Irongeek

    Dangerous free thinker

  • Agents of the Revolution
  • 1,516 posts
  • Location:Louisville, Ky more or less

Posted 08 May 2006 - 08:45 AM

Take the code here:
http://irongeek.com/...=security/igsig
and add a little.

#4 Fish

Fish

    H4x0r

  • Members
  • 37 posts

Posted 08 May 2006 - 10:17 PM

Will the code replax posted actually log the IP address, or will it just display it?

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 replax

replax

    Hakker addict

  • Members
  • 505 posts

Posted 08 May 2006 - 10:47 PM

that fopen fwrite fclose part will write to a file. I forgot to set a filename, so it would never work. I modified the post and now that's set. That will write the ip and timestamp to file.

#6 replax

replax

    Hakker addict

  • Members
  • 505 posts

Posted 09 May 2006 - 01:25 AM

without knowing what error message it is, i cannot say what is wrong.
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 Fish

Fish

    H4x0r

  • Members
  • 37 posts

Posted 09 May 2006 - 06:52 PM

Parse error: syntax error, unexpected T_STRING in H:\*******\public_html\upload\ip.php on line 9

#8 replax

replax

    Hakker addict

  • Members
  • 505 posts

Posted 09 May 2006 - 10:31 PM

i was missing a ;

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 chaostic

chaostic

    rekcah-rebÜ

  • Members
  • 724 posts

Posted 14 May 2006 - 09:38 PM

Now, do I need to name the script *.php to run correctly? Or can I name it .j or .jpg?

#10 BrakeDanceJ

BrakeDanceJ

    Hakker addict

  • Binrev Financier
  • 598 posts
  • Location:Chicago

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 replax

replax

    Hakker addict

  • Members
  • 505 posts

Posted 15 May 2006 - 09:02 AM

yes, unless you have done something tricky with a .htaccess, it needs to be a .php.

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 chaostic

chaostic

    rekcah-rebÜ

  • Members
  • 724 posts

Posted 18 May 2006 - 12:36 AM

Well, good news and bad news. Good news is that I can now log ip and times. Bad news is, I can't add a php script to my crappy host and to myspace (Anything with .php gets parsed out to "..").

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 :D

#13 replax

replax

    Hakker addict

  • Members
  • 505 posts

Posted 18 May 2006 - 10:02 AM

to all who care:

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!