/    Sign up×
Community /Pin to ProfileBookmark

Simple Array Problem

hi am having problems with this it just doesnt work

[code=php]
<?php

$ip = $_SERVER[“REMOTE_ADDR”];
$banned = file(“ips.php”);

$num = 0;
while(array_key_exists($num, $banned)) {
if($banned[$num] == $ip) {
exit(“You Have Been Banned From This Chat Room1″);
} else {
echo $banned[$num].”<br>”;
}
$num++;
}

if(in_array($ip, $banned)) {
exit(“You Have Been Banned From This Chat Room2″);
}

echo $ip.”<br>”;
print_r($banned);

?>
[/code]

but why? simple simple php, i have just coded a 78kB command file for this and now i come to do something comparativly trivial ‘IP blocking’ its not working, any ideas?

[url]http://www.richardturner.com/chat/ip.php[/url]

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@silent11Nov 24.2004 — from the docs:


Note: Each line in the resulting array will include the line ending, so you still need to use rtrim() if you do not want the line ending present.



http://us2.php.net/function.file


you may need to use this as 168.12.124.21n does not equal 168.12.124.21 .
Copy linkTweet thisAlerts:
@96turnerriauthorNov 24.2004 — thanks, didnt know that, learn something new everyday ?

final code
[code=php]<?php
$ip = $_SERVER["REMOTE_ADDR"]."n";
$banned = file("ips.php");
if(in_array($ip, $banned)) {
exit("You Have Been Banned From This Chat Room");
}
?>[/code]
Copy linkTweet thisAlerts:
@silent11Nov 24.2004 — ...learn something new everyday[/quote]

Me too, PHP has more built-in global functions than you can shake a stick at.
×

Success!

Help @96turnerri spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.10,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...