Jump to content

Fgets () Problem


es131245
 Share

Recommended Posts

I want to use txt ip ban list but my code doent work here it is$ip=getenv("REMOTE_ADDR");if ($ip !="::1"){$open_ban_list=fopen("ban_list.txt","r") or die("Cant open <i>BAN LIST</i>");while (! feof($open_ban_list)){$banned_ips=fgets($open_ban_list,1024);if ($ip == $banned_ips) {die ("you $ip is banned");}echo $banned_ips;}fclose($open_ban_list);$access_log_open=fopen("log.txt",a) or die("Cant open <i>ACCESS LOGS</i>");fwrite($access_log_open,date("H:i").date(":s")." ".date("j/n/Y")." ".$ip."\n");fclose($access_log_open);}?>All I get is echo $banned_ips;but die ("you $ip is banned"); doent "die"

Link to comment
Share on other sites

First, I don't think that REMOTE_ADDR is an environment variable. Have you printed $ip to verify it contains the right data? You should probably get that from $_SERVER instead.Second, you're comparing the IP with the entire contents of the text file. That's only going to work if the text file contains a single IP. I don't know how you're saving IPs in the file, but you need to break up the list of IPs and compare each one with the IP you're testing against.

Link to comment
Share on other sites

ive usedecho $banned_ips;for comparing and it echoed fine but its still doent work and i think ive tryed $_SERVERbut i got long banned ip list... now ive deleted ip banners cuz its realy alot of people doent have current ip...

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...