dotson Posted June 16, 2007 Share Posted June 16, 2007 I'm new to php and need a little help. The problem is the script always runs the else statement no matter what. I think I'm not using the "in_array" as I should or something. Anyway any help would be great. Here's the code... <?php $ip =$_SERVER["REMOTE_ADDR"]; $ips=file("ip-log.txt"); if(in_array($ip,$ips)) { $fp= fopen("ip-log.txt","a")or die('can\'t open file ip-log'); fwrite($fp,"$ip \n")or die('can\'t write to file ip-log'); fclose($fp)or die('can\'t close file ip-log'); echo "your ip is not unique"; } else { $uh=fopen("uip-log.txt","a")or die('can\'t open file uip-log'); fwrite($uh,"$ip \n")or die('can\'t write to file uip-log'); fclose($uh)or die('can\'t close file uip-log'); echo "your ip is unique"; $fp= fopen("ip-log.txt","a")or die('can\'t open file ip-log'); fwrite($fp,"$ip \n")or die('can\'t write to file ip-log'); fclose($fp)or die('can\'t close file ip-log'); } ?> Link to comment https://forums.phpfreaks.com/topic/55803-solved-ifin_array-not-working-right/ Share on other sites More sharing options...
emehrkay Posted June 16, 2007 Share Posted June 16, 2007 have you tried to print_r($ips) to see what the array looks like? the key value pairs may be different than you expect Link to comment https://forums.phpfreaks.com/topic/55803-solved-ifin_array-not-working-right/#findComment-275650 Share on other sites More sharing options...
dotson Posted June 16, 2007 Author Share Posted June 16, 2007 I figured it out. I had white space so I had to use trim to clean it up. <?php $ip =$_SERVER["REMOTE_ADDR"]; $ips =file("ip-log.txt"); $ips =array_map("trim", $ips); if(in_array($ip,$ips)){bla bla bla... Link to comment https://forums.phpfreaks.com/topic/55803-solved-ifin_array-not-working-right/#findComment-275654 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.