TheElemethian Posted August 23, 2009 Share Posted August 23, 2009 So, I'm new at this stuff, obviously, and I'm attempting to use this script that, when all is said and done, will log the computers IP address that loads the image. I start with a folder on my FTP called "tracker" Inside of tracker is another folder called "log" Files inside of tracker: moo.gif track.php login.htm admin.php track.php includes: <? $image = "moo.gif" ; $id = $_GET['id'] ; $logfile= "log/$id.htm"; $IP = $_SERVER['REMOTE_ADDR']; $logdetails= date("F j, Y, g:i a") . ': ' . '<a href=http://dnsstuff.com/tools/city.ch?ip='.$_SERVER['REMOTE_ADDR'].'>'.$_SERVER['REMOTE_ADDR'].'</a>'; $imagedir = "" ; if (isset($image) { $imagepath = $imagedir.$image ; $imageinfo = getimagesize( $imagepath ); header( "Content-type: image/jpg" ); @readfile( $imagepath ); if(isset ($_COOKIE['identifier'])){ $visitorid = $_COOKIE['identifier']; $visitornumber = " Visitor ID: $visitorid"; } else{ $r1 = rand (0, 9); $r2 = rand (0, 9); $r3 = rand (0, 9); $r4 = rand (0, 9); $r5 = rand (0, 9); $r6 = rand (0, 9); $r7 = rand (0, 9); $r8 = rand (0, 9); $r9 = rand (0, 9); $rnumber = $r1.$r2.$r3.$r4.$r5.$r6.$r7.$r8.$r9; setcookie("identifier", $rnumber, time()+155520000); $visitornumber = " Visitor ID: $rnumber"; } $fp = fopen($logfile, "a"); fwrite($fp, $logdetails.$visitornumber ); fwrite($fp, "<br>"); fclose($fp); } else { header( "HTTP/1.0 404 Not Found" ); exit ; } ?> Login.htm: <html> <head> <title>Tracker Login</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body> <form action="admin.php" method="get"><table width="575" border="0" align="center" cellpadding="5" cellspacing="5"> <!--DWLayoutTable--> <tr> <td height="31" colspan="6" valign="top"><div align="center"><strong><font face="Verdana, Arial, Helvetica, sans-serif">Login Below </font></strong></div></td> </tr> <tr> <td width="33" height="25"></td> <td width="118"></td> <td width="80"></td> <td width="85"></td> <td width="114"></td> <td width="50"></td> </tr> <tr> <td height="32"> </td> <td colspan="2" valign="top"><font face="Verdana, Arial, Helvetica, sans-serif">Enter your ID number</font></td> <td colspan="2" valign="top"> <input size="35" name="id" type="text"> </td> <td></td> </tr> <tr> <td height="17"></td> <td></td> <td></td> <td></td> <td></td> <td></td> </tr> <tr> <td height="34"></td> <td></td> <td colspan="2" align="center" valign="middle"><input type="submit" name="Submit" value="Submit" action="get"></td> <td> </td> <td> </td> </tr> <tr> <td height="58"></td> <td></td> <td> </td> <td> </td> <td> </td> <td> </td> </tr> </table> </form> </body> </html> admin.php: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>Visitor Detail</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body> <table align="center" width="855" border="0" cellpadding="0" cellspacing="0"> <!--DWLayoutTable--> <tr> <td align="center" width="855" height="245"> <? $id = $_GET['id'] ; $myFile = "log/$id.htm"; $fh = fopen($myFile, 'r'); $theData = fread($fh, filesize($myFile)); fclose($fh); echo $theData; ?> </td> </tr> </table> </body> </html> Here is the site that I got the code from: http://www.soggycowdesigns.com/tests/myspacetracker.htm And www.theelemethian.com/tracker/info.php is my host info. I use Bluehost. Here is what I get when I try to login: Warning: fopen(log/13.htm) [function.fopen]: failed to open stream: No such file or directory in /home2/onethrt5/public_html/theelemethian/tracker/admin.php on line 17 Warning: filesize() [function.filesize]: stat failed for log/13.htm in /home2/onethrt5/public_html/theelemethian/tracker/admin.php on line 18 Warning: fread(): supplied argument is not a valid stream resource in /home2/onethrt5/public_html/theelemethian/tracker/admin.php on line 18 Warning: fclose(): supplied argument is not a valid stream resource in /home2/onethrt5/public_html/theelemethian/tracker/admin.php on line 19 I hope this is just a simple fix, but if it is, I'll feel dumber than I do. I really appreciate any help that you guys can give. Thanks! Link to comment https://forums.phpfreaks.com/topic/171488-solved-ip-log-image-loader-not-working/ Share on other sites More sharing options...
markwillis82 Posted August 23, 2009 Share Posted August 23, 2009 Warning: fopen(log/13.htm) [function.fopen]: failed to open stream: No such file or directory in /home2/onethrt5/public_html/theelemethian/tracker/admin.php on line 17 This looks like either php has not got the correct permissions to create the log file in the directory - or the folder doesn't exist. Check all folders exist. It may be worthwhile making the log folder world writable for some testing Link to comment https://forums.phpfreaks.com/topic/171488-solved-ip-log-image-loader-not-working/#findComment-904344 Share on other sites More sharing options...
TheElemethian Posted August 23, 2009 Author Share Posted August 23, 2009 Well, I'll look into allowing access. Which I will find the answer to elsewhere, unless someone knows off the top of their head. But what all folders are supposed to exist? Link to comment https://forums.phpfreaks.com/topic/171488-solved-ip-log-image-loader-not-working/#findComment-904551 Share on other sites More sharing options...
markwillis82 Posted August 23, 2009 Share Posted August 23, 2009 Warning: fopen(log/13.htm) [function.fopen]: failed to open stream: No such file or directory in /home2/onethrt5/public_html/theelemethian/tracker/admin.php on line 17 i'm guessing from this error message: the "log" folder should be in ... /home2/onethrt5/public_html/theelemethian/tracker/log/ Link to comment https://forums.phpfreaks.com/topic/171488-solved-ip-log-image-loader-not-working/#findComment-904620 Share on other sites More sharing options...
TheElemethian Posted August 23, 2009 Author Share Posted August 23, 2009 :/ Alright, well. I created the necessary folders, and allowed writing to them. But it returns the same message. Line 17 in admin.php: $fh = fopen($myFile, 'r'); While the lines just before that are attempting to define $myfile Should I just try to manually define a file for this to log the information I want? Link to comment https://forums.phpfreaks.com/topic/171488-solved-ip-log-image-loader-not-working/#findComment-904633 Share on other sites More sharing options...
TheElemethian Posted August 23, 2009 Author Share Posted August 23, 2009 Warning: fread() [function.fread]: Length parameter must be greater than 0 in /home2/onethrt5/public_html/theelemethian/tracker/admin.php on line 18 when I attempted to manually define the $myFile string. Edited admin.php lines 14-20: <? $id = $_GET['id'] ; $myFile = "og/log.htm"; $fh = fopen("log/log.htm[", 'r'); $theData = fread($fh, filesize("log/log.htm")); fclose($fh); echo $theData; ?> Link to comment https://forums.phpfreaks.com/topic/171488-solved-ip-log-image-loader-not-working/#findComment-904641 Share on other sites More sharing options...
TheElemethian Posted August 23, 2009 Author Share Posted August 23, 2009 Or is there some other way to embed a script (or image) into an HTML message, and record the IP that loads it? I don't care about the login, or anything. I just want the IP Address. Link to comment https://forums.phpfreaks.com/topic/171488-solved-ip-log-image-loader-not-working/#findComment-904679 Share on other sites More sharing options...
markwillis82 Posted August 23, 2009 Share Posted August 23, 2009 ok - found a few bugs.... in track.php line 8: if (isset($image) { should be if (isset($image)) { this should then allow the tracker image to work. http://www.theelemethian.com/tracker/track.php?id=1 something like this. (currently displays an error message) <? $id = $_GET['id'] ; $myFile = "log/$id.htm"; $fh = fopen($myFile, 'r'); $theData = fread($fh, filesize($myFile)); fclose($fh); echo $theData; ?> is returning an error because the file does not exist (if the track.php isn't working it's not creating the file) so it might be worth putting a try/catch block around the code or alternativly use file_exists() in an if block. But if you are using this as a form of tracking, you will quickly generate alot of files. It may be worth using a database backend (quicker to access and alot less disk IO) If you want to track every page hit, etc. (including googlebot and other crawlers) i'm currently building an open source project "crawler catcher" which is currently in alpha stage, once i'm happy with the code base I will release the code in BETA to hopefully get some more coverage. http://mwillis.co.uk/crawler-catcher/ < - link to more info. I hope this helps Mark Link to comment https://forums.phpfreaks.com/topic/171488-solved-ip-log-image-loader-not-working/#findComment-904695 Share on other sites More sharing options...
TheElemethian Posted August 23, 2009 Author Share Posted August 23, 2009 Really? REALLY? You're kidding me. It works now. Gahh. Hahahah. Thank you so much, Mark! Link to comment https://forums.phpfreaks.com/topic/171488-solved-ip-log-image-loader-not-working/#findComment-904732 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.