My second question. See the script would read a text file with ip and hostmask that the user has entered, if the hostmask and ip matches, the user would be redirected to a new page where it tells you are banned from the website. Please help
Random Banner/ Ip/Hostmask ban
Moderator: General Moderators
Random Banner/ Ip/Hostmask ban
how do i make a random banner rotating thing. Means, the code will read a text file containing links to all images (each link in a new line). It will select a random banner and display it. This is my first question.
My second question. See the script would read a text file with ip and hostmask that the user has entered, if the hostmask and ip matches, the user would be redirected to a new page where it tells you are banned from the website. Please help
My second question. See the script would read a text file with ip and hostmask that the user has entered, if the hostmask and ip matches, the user would be redirected to a new page where it tells you are banned from the website. Please help
Code: Select all
<?php
$banned = file('/path/to/bannedIP.txt'); // read banned ips to an array (one line->one element)
$banned = array_flip($banned); // is_set() is faster than in_array()
if (is_set($banned[$_SERVER['REMOTE_ADDR']])
die("you're banned");
$links = file('/path/to/links.txt'); // read all links to an array (one line->one element, numerical indices)
srand((double)microtime()*1000000); // initialize rand-generator
$idx = rand(0, count($links)-1); // a random index "within" $links
?>
<img src="http://server.url/<?php echo $links[$idx]; ?>" />hostmasks are a bit more complex
and I'm too tired for that right now
oops, I forgot something. The elements of $banned will have a trailing CR/LF.
Code: Select all
$banned = file('/path/to/bannedIP.txt'); // read banned ips to an array (one line->one element)
$banned = array_map('trim', $banned); // get rid of whitespaces
$banned = array_flip($banned); // is_set() is faster than in_array()I used this
I used this code
Code: Select all
<?php
$banned_person = file('banned.txt');
foreach($banned_person as $banned) {
$ip = $_SERVER['REMOTE_ADDR'];
if($ip == $banned){
echo "The ip is banned, sorry, you can't view this page!";
exit();
}
}
?>you still need to get rid of the CR/LF.because "127.0.0.1" is not equal to "127.0.0.1\n"
Code: Select all
$banned_person = file('banned.txt');
$banned = array_map('trim', $banned); // applies trim() to all elements.
foreach($banned_person as $banned) {http://www.php.net/manual/en/function.file.php wrote:Note: Each line in the resulting array will include the line ending, so you still need to use trim() if you do not want the line ending present.