SirEddie Posted May 14, 2007 Share Posted May 14, 2007 Hey all I have this script: <?php $file = "ip.txt"; $write = "".$_SERVER['REMOTE_ADDR']."|--|"; $open = fopen($file, 'a'); fwrite($open, $write); ?> Which writes the visitors Ip to the file "ip.txt". Now, it writes them across like this: 'IP IP IP IP IP IP IP" and it is confusing to read. I waas wondering, is there a way I can make it write them like this:? IP IP IP IP Also, make it so it only writes the same IP once? Quote Link to comment Share on other sites More sharing options...
neel_basu Posted May 14, 2007 Share Posted May 14, 2007 use this $write = $_SERVER['REMOTE_ADDR']."\n"; ------------------------------------------ Donno why you were using the "" at the begening Quote Link to comment Share on other sites More sharing options...
SirEddie Posted May 14, 2007 Author Share Posted May 14, 2007 Thanks mate Any idea on only the same IP once? Quote Link to comment Share on other sites More sharing options...
neel_basu Posted May 14, 2007 Share Posted May 14, 2007 Compleately Untested -------------------------------- <?php $str = file_get_contents('ip.txt'); $line = explode("\n", $str); $flag = true; foreach($line as $val) { if($ip == $val) { $flag = false; } } if($flag) { //Write the Files to the file } ?> Quote Link to comment Share on other sites More sharing options...
SirEddie Posted May 14, 2007 Author Share Posted May 14, 2007 Thanks.. I'll give it a shot Quote Link to comment Share on other sites More sharing options...
SirEddie Posted May 14, 2007 Author Share Posted May 14, 2007 <?php $str = file_get_contents('ip.txt'); $line = explode("\n", $str); $flag = true; foreach($line as $val) { if($ip == $val) { $flag = false; } } if($flag) { $file = "ip.txt"; $write = $_SERVER['REMOTE_ADDR']."\n"; $open = fopen($file, 'a'); fwrite($open, $write); } ?> I have it set like that.. But now it doesn't write any IP's.. Any ideas? Quote Link to comment Share on other sites More sharing options...
neel_basu Posted May 14, 2007 Share Posted May 14, 2007 Use if($_SERVER['REMOTE_ADDR'] == $val) Quote Link to comment Share on other sites More sharing options...
SirEddie Posted May 14, 2007 Author Share Posted May 14, 2007 Where abouts? Sorry, I am a bit new to php. Quote Link to comment Share on other sites More sharing options...
neel_basu Posted May 14, 2007 Share Posted May 14, 2007 <?php $str = file_get_contents('ip.txt'); $line = explode("\n", $str); $flag = true; foreach($line as $val) { if($_SERVER['REMOTE_ADDR'] == $val) { $flag = false; } } if($flag) { $file = "ip.txt"; $write = $_SERVER['REMOTE_ADDR']."\n"; $open = fopen($file, 'a'); fwrite($open, $write); } ?> Quote Link to comment Share on other sites More sharing options...
SirEddie Posted May 14, 2007 Author Share Posted May 14, 2007 Thanks heaps mate! Works like a charm Quote Link to comment Share on other sites More sharing options...
neel_basu Posted May 14, 2007 Share Posted May 14, 2007 First I thought you are keeping The Ip i $ip Quote Link to comment Share on other sites More sharing options...
SirEddie Posted May 14, 2007 Author Share Posted May 14, 2007 Ah.. I see.. Thanks for all your help Have a good one 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.