MistyEyes Posted July 4, 2008 Share Posted July 4, 2008 Hello, This is my 1st time here. I will say I know nothing about php! I know I have it on my server. What I am trying to do is log and ip of whom ever clicks on a certain picture. I am using a nice, simple script. I get an error when trying to write the log. Here is the part that is giving the error: //here, we open the logfile for writing to. The 'a' means when we write // data to the text file, it will be appended to the end of the file $fh = fopen($logs, 'a') or die(" "); And this is the error, which is on line 18: Warning: fopen(http://www.mysite.com/ip_log/logs.txt): failed to open stream: HTTP wrapper does not support writeable connections. in /home/me/mysite/picture.jpg/index.php on line 18 what do I need to do NOT to get that error? Thank you so much, in advance! Quote Link to comment Share on other sites More sharing options...
fanfavorite Posted July 4, 2008 Share Posted July 4, 2008 You cannot open a file using fopen with a url like http://www.mysite.com/ip_log/logs.txt. You need to make it /home/me/mysite/ip_logs/logs.txt. Quote Link to comment Share on other sites More sharing options...
MistyEyes Posted July 4, 2008 Author Share Posted July 4, 2008 I changed it as you suggested, and received another error on another line. I am going to post the raw script so you can see actually what I am working with. <?php // Ip recorder, use in the format yoursite.com/picture.jpg/index.php //this picture variable defines which image to show the victim $picture = "http://mysite.com/w/w060529_2.jpg"; //this line just gets the visitor's ip address and stores it in the variable '$ip' $ip = $_SERVER['REMOTE_ADDR']; //this line tells the logger the name you want to use for the log file. // if the logfile doesn't already exist, it will be created automagically $logs = "logs.txt"; //here, we open the logfile for writing to. The 'a' means when we write // data to the text file, it will be appended to the end of the file $fh = fopen($logs, 'a') or die(" "); //here we put the ip address into a variable called 'string data' // the backslash-n starts a new line in the text file, to make it easier to read $stringData = "$ip \n"; //here we write to the text file what is in the stringdata variable fwrite($fh, $stringData); //now we close the file fclose($fh); //and finally we echo some html back to the user's browser so they see an image echo "<img src='$picture'>"; ?> thanks again! Quote Link to comment Share on other sites More sharing options...
SharkBait Posted July 4, 2008 Share Posted July 4, 2008 What was the error you received now? Quote Link to comment Share on other sites More sharing options...
fanfavorite Posted July 4, 2008 Share Posted July 4, 2008 I don't see a problem with the code posted at first glance. Please post the error you are receiving. Quote Link to comment Share on other sites More sharing options...
MistyEyes Posted July 4, 2008 Author Share Posted July 4, 2008 Sorry for the delayed reply, but lots of thunder and lightning causes my adsl to stop, then go then stop .... The error I now receive is: Warning: fopen(/me/mysite/ip_logs/logs.txt): failed to open stream: No such file or directory in /home/me/my site/picture.jpg/index.php on line 19 which is here - //here, we open the logfile for writing to. The 'a' means when we write // data to the text file, it will be appended to the end of the file $fh = fopen($logs, 'a') or die(" "); Quote Link to comment Share on other sites More sharing options...
DarkWater Posted July 4, 2008 Share Posted July 4, 2008 Read the error....there's no such directory or file....so make an ip_logs directory and it should create the file automatically. Quote Link to comment Share on other sites More sharing options...
MistyEyes Posted July 4, 2008 Author Share Posted July 4, 2008 This is nutz! I had that dir, with the txt file there. I changed the name from logs to log, and now I am getting yet another error Warning: fopen(/home/me/mysite/ip_logs/log.txt): failed to open stream: Permission denied in /home/me/mysite/PHONEYPIC.jpg/index.php on line 18 Line 18 is: $fh = fopen($logs, 'a') or die(" "); Quote Link to comment Share on other sites More sharing options...
br0ken Posted July 4, 2008 Share Posted July 4, 2008 The error indicates that you (the user running PHP) doesn't have write permissions for the folder you'r trying to write to. You would need to change these permissions and it should run ok. Quote Link to comment Share on other sites More sharing options...
MistyEyes Posted July 4, 2008 Author Share Posted July 4, 2008 YIPEEEEEEEEE! Now THAT last one made me feel 'tupid with a CAP "T" I had it semi working before with the correct permissions, and when I changed the files, I forgot to re-CHMOD the file. (and it actually logged my ip) I want to thank every one that helped me with this! You are all wonderful and you were VERY gentle with me! ha ha ha! Quote Link to comment Share on other sites More sharing options...
MistyEyes Posted July 4, 2008 Author Share Posted July 4, 2008 I almost forgot ... I wanted to ask .. maybe you know ... Is there a way to see past a user that comes to a site via proxy? To see the REAL ip, not the proxy's ip. Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted July 4, 2008 Share Posted July 4, 2008 check the following PHP Functions: ip2long getenv Quote Link to comment Share on other sites More sharing options...
MistyEyes Posted July 4, 2008 Author Share Posted July 4, 2008 remember ... php noob here..LOL... Is that a different kind of php script used to break the proxy to the real ip? (I have to learn this!) I will check back here later, as we are going to a 4th party. BBL and thank you all again! Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted July 4, 2008 Share Posted July 4, 2008 <?php //List of the private ips described in the RFC. You can easily add the //127.0.0.0/8 to this if you need it. $ip_private_list=array( "10.0.0.0/8", "172.16.0.0/12", "192.168.0.0/16" ); //Determine if an ip is in a net. //E.G. 120.120.120.120 in 120.120.0.0/16 //I saw this in another post in this site but don't remember where function isIPInNet($ip,$net,$mask) { $lnet=ip2long($net); $lip=ip2long($ip); $binnet=str_pad( decbin($lnet),32,"0","STR_PAD_LEFT" ); $firstpart=substr($binnet,0,$mask); $binip=str_pad( decbin($lip),32,"0","STR_PAD_LEFT" ); $firstip=substr($binip,0,$mask); return(strcmp($firstpart,$firstip)==0); } //This function check if a ip is in an array of nets (ip and mask) function isIpInNetArray($theip,$thearray) { $exit_c=false; #print_r($thearray); foreach ( $thearray as $subnet ) { list($net,$mask)=split("/",$subnet); if(isIPInNet($theip,$net,$mask)){ $exit_c=true; break; } } return($exit_c); } //Building the ip array with the HTTP_X_FORWARDED_FOR and //REMOTE_ADDR HTTP vars. //With this function we get an array where first are the ip's listed in //HTTP_X_FORWARDED_FOR and the last ip is the REMOTE_ADDR. //This is inspired (copied and modified) in the function from daniel_dll. function GetIpArray() { $cad=""; if (isset($_SERVER['HTTP_X_FORWARDED_FOR']) AND $_SERVER['HTTP_X_FORWARDED_FOR']!="") $cad=$_SERVER['HTTP_X_FORWARDED_FOR']; if(isset($_SERVER['REMOTE_ADDR']) AND $_SERVER['REMOTE_ADDR']!="") $cad=$cad.",".$_SERVER['REMOTE_ADDR']; $arr= explode(',',$cad); return $arr; } //We check each ip in the array and we returns the first that is not a //private ip. function getIp() { global $ip_private_list; $ip = "unknown"; $ip_array=getIpArray(); foreach ( $ip_array as $ip_s ) { if( $ip_s!="" AND !isIPInNetArray($ip_s,$ip_private_list)){ $ip=$ip_s; break; } } return($ip); } ?> Quote Link to comment Share on other sites More sharing options...
MistyEyes Posted July 5, 2008 Author Share Posted July 5, 2008 Good morning all! darkfreaks: Thank you for posting that. This is going to be used for a toplist. There is a jerk that has been a royal pain and is posting non sites every day many times a day. All of the files for the toplist are in my cgi dir. So where will this go, where will I see the readout, and what do I call it ?? Thank you Thank you Thank you !!! Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted July 5, 2008 Share Posted July 5, 2008 a toplist for ip's i spose ??? let me tell you how the functions work first off then you can call them how you want to. private list allows you to manually input and array private IP's. the function ipisinnet determines if an IP adress is in the same network or not. the second function under it determines if it is in multiple networks and hidden (IE a proxy). the last function gets all of the arrayed IP's and the very very last function searches all the arrayed IP's to make sure it isnt listed as a private IP and if it is it returns one that is not a private hidden IP (IE a proxy) Quote Link to comment Share on other sites More sharing options...
MistyEyes Posted July 5, 2008 Author Share Posted July 5, 2008 Let me go into more detail. When someone signs up to add a site to the toplist, I receive an email saying that they did so. I am still confused as to where to put this script, and how to get it to output where I can see the results. Like the 1st script that I posted ... It creates a log of the user's ip by having them hopefully click on the picture. Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted July 5, 2008 Share Posted July 5, 2008 you can go here and download a banmod this guy made. it checks for proxies. so if your real ip is banned and you try to use a proxy to get around it , it will check. http://www.ozzu.com/unix-linux-forum/mass-proxy-ban-mod-t31433.html Quote Link to comment Share on other sites More sharing options...
MistyEyes Posted July 5, 2008 Author Share Posted July 5, 2008 awesome! TY! I will check it out Quote Link to comment Share on other sites More sharing options...
MistyEyes Posted July 5, 2008 Author Share Posted July 5, 2008 That was a complete bust. 404 errors, and servers are gone. Any other suggestions? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.