Banned IP Override

Dr. GBooky is here to help you with your guestbook problems ...
Post Reply
steel8ball
Posts: 9
Joined: Mon Oct 20, 2008 10:55 pm

Banned IP Override

Post by steel8ball »

Firstly, the Guestbook works perfectly. Sometimes too good.

Is there any way to override the Banned IP text file to allow certain specific IP Addresses? The problem lies with a company I'm using to host a website with the PHP Guestbook Script and their PHP Server sometimes, automatically queries the PHP Guestbook, but since it is an automatic query, the IP Address from their PHP Server gets put in the banned IP text file and results in the Guestbook disappearing to a blank white page. Until I remove the banned IP Address from the text file, the Guestbook will stay blank. This is kinda a hassle to remove the banned IP Address this all the time, which is why I'm asking if there is a way to override the banned IP text file to always allow certain specific automated IP Addresses?

Thanks for your help. Jim :?:
Klemen
Site Admin
Posts: 10116
Joined: Fri Feb 11, 2005 4:04 pm

Post by Klemen »

Try replacing this code in gbook.php

Code: Select all

$ip = gbook_IP();
with

Code: Select all

$ip = gbook_IP(); if($ip == 'XXX.XXX.XXX.XXX'){return true;}
where XXX.XXX.XXX.XXX is the IP you want to allow.
Klemen, creator of HESK and PHPJunkyardWas this helpful? You can buy me a drink here Image

Image You should follow me on Twitter here

Help desk software | Cloud help desk | Guestbook | Link manager | Click counter | more PHP Scripts ...

Also browse for php hosting companies, read php books, find php resources and use webmaster tools
steel8ball
Posts: 9
Joined: Mon Oct 20, 2008 10:55 pm

GBook PHP IP Address Blocking Override

Post by steel8ball »

Thanks for that reply. I'll try that. However, if there are several IP Addresses that need to be allowed (3 for example), how would I code that into the code you gave me to try?

Thanks, Jim
Klemen
Site Admin
Posts: 10116
Joined: Fri Feb 11, 2005 4:04 pm

Post by Klemen »

Code: Select all

$allowed_ips = array('XXX.XXX.XXX.1','XXX.XXX.XXX.2','XXX.XXX.XXX.3');

$ip = gbook_IP(); if(in_array($ip, $allowed_ips)){return true;}
Klemen, creator of HESK and PHPJunkyardWas this helpful? You can buy me a drink here Image

Image You should follow me on Twitter here

Help desk software | Cloud help desk | Guestbook | Link manager | Click counter | more PHP Scripts ...

Also browse for php hosting companies, read php books, find php resources and use webmaster tools
steel8ball
Posts: 9
Joined: Mon Oct 20, 2008 10:55 pm

Guest Book IP Blocking Override

Post by steel8ball »

Thanks for that response too. I'll try that. I really like your Guest Book. One of the best things I like about it is the IP Blocking even though it has been blocking IP's from the PHP Server itself, still, it has been keeping the Guest Book clean and tidy. Thanks for your hard work creating this PHP Guest Book. Sincerely, Jim
steel8ball
Posts: 9
Joined: Mon Oct 20, 2008 10:55 pm

Update On The Banned IP Over-ride PHP Code Function

Post by steel8ball »

The code to allow certain IP Addresses past the Banned IP spam protection works to an extent and the Guest Book doesn't cause a blank page anymore when certain IP Addresses from the Yahoo PHP Server communicate with the PHP Guest Book. However, the main issue lies now in wanting to see the IP Addresses of each post. The actual IP Address of the post does not display; the IP Address that is shown from each post is the IP Addresses allowed to over-ride the Banned IP spam protection function. So, if there is, like in my case, 3 IP Addresses you wanted to allow to over-ride the Banned IP spam protection function of the Guest Book, then each post will only show one of those 3 IP Addresses, not their true IP Address. Another minor point from using this code is, even though I allowed the 3 IP Addresses to over-ride the Guest Book spam protection, they still show up in the Banned IP text file. Still though, I will use the code to over-ride the spam protection of the Guest Book because it prevents the Guest Book from showing a blank page every time the Yahoo PHP Server communicates with the PHP Guest Book. Also, the Guest Book spam protection still functions as normal using this code. It's a shame that Yahoo changed something on their PHP Server recently to cause this issue, but they might have some sort of reason for it...who knows. I've asked their PHP Server Support about what and why things were changed, but either they won't answer or don't really understand the repercussions of the changes they made. However, like I said, at least the Guest Book functions fine and I don't get a blank page anymore. These little issues with the code is a small price to pay for a great Guest Book. I just wanted to share this with everyone especially Klemen if you decide to incorporate this function into future updates of the Guest Book. This way you will know how it reacts with the Guest Book code and function. Thanks, Jim
Klemen
Site Admin
Posts: 10116
Joined: Fri Feb 11, 2005 4:04 pm

Post by Klemen »

I'm not sure what you edited, but this shouldn't happen if you correctly modified the code as IP is always assigned just from $_SERVER['REMOTE_ADDR']. Post your code from

Code: Select all

function gbook_IP() {
to the end of gbook.php file here and I will have a look.
Klemen, creator of HESK and PHPJunkyardWas this helpful? You can buy me a drink here Image

Image You should follow me on Twitter here

Help desk software | Cloud help desk | Guestbook | Link manager | Click counter | more PHP Scripts ...

Also browse for php hosting companies, read php books, find php resources and use webmaster tools
steel8ball
Posts: 9
Joined: Mon Oct 20, 2008 10:55 pm

Post by steel8ball »

I put the code in exactly as you stated above. It's possible it's some goofy thing with the Yahoo PHP Server itself. Another thing they have wrong with their PHP Server is the date. Apparently, they don't check that too well because each post tends to be a few hours off. I know this because of what people have told me. They would make a post at around 8pm on October 27, 2008 and the post would read October 28, 2008 instead. I know this issue is not from your code, but from their PHP Server.

Anyway, here's the code:

Code: Select all

function gbook_IP() {
    $ip = $_SERVER['REMOTE_ADDR'];
    if (!preg_match('/^[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}$/',$ip))
    {
        if ($settings['allow_IPv6'] && preg_match('/^[0-9A-Fa-f\:]+$/',$ip))
        {
            return $ip;
        }
        die($lang['e20']);
    }
    return $ip;
} // END gbook_IP()

function gbook_CheckIP() {
	 $allowed_ips = array('216.39.62.189','216.39.62.190','216.39.62.191');
    $ip = gbook_IP(); if(in_array($ip, $allowed_ips)){return true;}
    $myBanned = file_get_contents('banned_ip.txt');
    if (strpos($myBanned,$ip) !== false) {
        die($lang['e21']);
    }
    return true;
} // END gbook_CheckIP()
Thanks, Jim
steel8ball
Posts: 9
Joined: Mon Oct 20, 2008 10:55 pm

Post by steel8ball »

The rest of the code after what I posted above is still the same as you coded it, but I figured I should post the entire code from "function gbook_IP() {" to the end like you said, so here it is:

Code: Select all

function gbook_IP() {
    $ip = $_SERVER['REMOTE_ADDR'];
    if (!preg_match('/^[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}$/',$ip))
    {
        if ($settings['allow_IPv6'] && preg_match('/^[0-9A-Fa-f\:]+$/',$ip))
        {
            return $ip;
        }
        die($lang['e20']);
    }
    return $ip;
} // END gbook_IP()

function gbook_CheckIP() {
	$allowed_ips = array('216.39.62.189','216.39.62.190','216.39.62.191');
    $ip = gbook_IP(); if(in_array($ip, $allowed_ips)){return true;}
    $myBanned = file_get_contents('banned_ip.txt');
    if (strpos($myBanned,$ip) !== false) {
        die($lang['e21']);
    }
    return true;
} // END gbook_CheckIP()

function gbook_banIP($ip,$doDie=0) {
    $fp=fopen('banned_ip.txt','a');
    fputs($fp,$ip.'%');
    fclose($fp);
    if ($doDie) {
        die($lang['e21']);
    }
    return true;
} // END gbook_banIP()

function gbook_session_regenerate_id() {
    if (version_compare(phpversion(),'4.3.3','>=')) {
       session_regenerate_id();
    } else {
        $randlen = 32;
        $randval = '0123456789abcdefghijklmnopqrstuvwxyz';
        $random = '';
        $randval_len = 35;
        for ($i = 1; $i <= $randlen; $i++) {
            $random .= substr($randval, rand(0,$randval_len), 1);
        }

        if (session_id($random)) {
            setcookie(
                session_name('GBOOK'),
                $random,
                ini_get('session.cookie_lifetime'),
                '/'
            );
            return true;
        } else {
            return false;
        }
    }
} // END gbook_session_regenerate_id()

?>
Thanks, Jim
Klemen
Site Admin
Posts: 10116
Joined: Fri Feb 11, 2005 4:04 pm

Post by Klemen »

Don't see any problems here, any way I can test your GBook?
Klemen, creator of HESK and PHPJunkyardWas this helpful? You can buy me a drink here Image

Image You should follow me on Twitter here

Help desk software | Cloud help desk | Guestbook | Link manager | Click counter | more PHP Scripts ...

Also browse for php hosting companies, read php books, find php resources and use webmaster tools
steel8ball
Posts: 9
Joined: Mon Oct 20, 2008 10:55 pm

Post by steel8ball »

I'd like that, but as far as logging into the account, well, I don't think those who I built the website for would want me to do that. If it was my website, I'd definitely let you, but since I built it for someone else, I don't think they would like for someone else logging into their Web Space. However, the URL is: www.brotherskeepersci.org . The php code for the Guest Book is linked to the php file, so the code is not within the HTML page itself. Makes it cleaner and easier to use that way.

I kinda believe it is more of a Yahoo Small Business Web Hosting thing with their PHP Server and not so much your code. I fear calling them because they don't sound too savvy. You know how technical support is sometimes.

This website has been going for about 6 months now and this issue with the Yahoo PHP Server communicating with the Guest Book only started maybe about a week ago or so. Therefore, it makes me wonder why this only started recently and not from day 1. That's why I think they changed something with their PHP Server settings.

At least the code you gave me to add prevents the blank page issue on the Guest Book from occuring anymore. That's the biggest thing.

Like I said, sorry I can't allow you to login to the web space since it isn't mine. However, here is a typical IP Address from a post (not their true IP because you can tracert it to Yahoo):

This post has been submitted from: 216.39.62.191 (p4p3.geo.re4.yahoo.com)

I could also be: 216.39.62.190 (p4p2.geo.re4.yahoo.com) or 216.39.62.191 (p4p1.geo.re4.yahoo.com)

Depends when the post is added. Really odd why it does that and annoys me, but at least the Guest Book doesn't go blank anymore.

If you can think of anything else to try, I'll be willing to change up the code because I didn't really change anything in the gbook.php file except for you giving me the above code to try and some more smilies (not an issue because these were added into the code day 1 of the website). Otherwise the code is the same as the download. Of course there are changes in the file, but that is necessary for it to work properly. Shouldn't be an issue there. You could actually copy the code I gave you above from the "function gbook_CheckIP() {" section into the downloaded version of your Guest Book and then it would really be the same as mine.

If you do that with your gbook.php code and test it and you can still see the posts actual IP address and not only the allowed IP Addresses, then I'd know the issue lies with Yahoo's PHP Server.

Thanks for anymore help you can give me, or even advice would be welcome.

Jim
Klemen
Site Admin
Posts: 10116
Joined: Fri Feb 11, 2005 4:04 pm

Post by Klemen »

Don't worry, I meant testing a guestbook not logging into any accounts :wink:

If you look inside your "entries.txt" file (I see you renamed it to something else so look inside that file) the last information is Yahoo's IP address? From what I see it is possible your Yahoo host is using some kind of proxy server (or a strange feature) to handle posts and the environment variable REMOTE_ADDR actually displays their IP and not the user's. To confirm this and possibly find a solution (if actual visitor's IP is in some other variable) upload phpinfo file to your server and post a link to it here:
http://www.phpjunkyard.com/extras/phpinfo.zip
Klemen, creator of HESK and PHPJunkyardWas this helpful? You can buy me a drink here Image

Image You should follow me on Twitter here

Help desk software | Cloud help desk | Guestbook | Link manager | Click counter | more PHP Scripts ...

Also browse for php hosting companies, read php books, find php resources and use webmaster tools
steel8ball
Posts: 9
Joined: Mon Oct 20, 2008 10:55 pm

Post by steel8ball »

I knew Yahoo changed something recently in their PHP Server settings. At least you are thinking along the same lines too.

OK. I'll do that with the phpinfo.php file. I knew about that, just wasn't thinking. Here's the link to the phpinfo.php file:

http://www.brotherskeepersci.org/phpinfo.php

When you spoke of the entries.txt file (I changed that to (gbookentries.txt), that is the posts in the Guest Book. Do you mean the banned_ip.txt file having the last IP Address as Yahoo's??? I normally go in the banned_ip.txt file and delete the Yahoo PHP Server IP's.

Thanks for all your help!

Jim
steel8ball
Posts: 9
Joined: Mon Oct 20, 2008 10:55 pm

Post by steel8ball »

Klemen,

You won't even believe this, the latest Guest Book post shows the actual IP Address of the host and not the IP of the Yahoo PHP Server. I really don't know what happened. I guess, maybe, the Yahoo PHP Admins fixed or changed something again. Anyway, like I began to think, your code you gave me to try is fine, it was Yahoo and the PHP Server. Anyway, thanks for your help. Seems the Guest Book is working properly in all respects based upon the latest Guest Book post.

Always something when it comes to Server configurations and settings. Never a dull moment.

Warm Regards,

Jim
Klemen
Site Admin
Posts: 10116
Joined: Fri Feb 11, 2005 4:04 pm

Post by Klemen »

You're welcome, I'm glad this is solved as it was a new one for me too.
Klemen, creator of HESK and PHPJunkyardWas this helpful? You can buy me a drink here Image

Image You should follow me on Twitter here

Help desk software | Cloud help desk | Guestbook | Link manager | Click counter | more PHP Scripts ...

Also browse for php hosting companies, read php books, find php resources and use webmaster tools
Post Reply