Author Topic: [PHP]blocking ip address from viewing site  (Read 18097 times)

0 Members and 1 Guest are viewing this topic.

Offline deadly7

  • 42
  • Moderator
  • Hero Member
  • *****
  • Posts: 6496
    • View Profile
[PHP]blocking ip address from viewing site
« on: August 05, 2005, 09:33:18 pm »
<?php
include "nav.html";
print 
"<font color=\"white\">"$_SERVER['REMOTE_ADDR'] ."</font>";
if 
$_SERVER['REMOTE_ADDR'] = 127.0.0.1 Then {
echo 
"<meta http-equiv=\"refresh\" content=\"5; url=http://www.mysite.com/dir/noview.php\" />" }
?>


Why doesn't it work?

Edit: Returns this message
Parse error: parse error, unexpected T_VARIABLE, expecting '(' in /home/deadly7/public_html/ on line 15
Quote
if $_SERVER['REMOTE_ADDR'] = 127.0.0.1 Then {
That is line 15.
« Last Edit: August 05, 2005, 09:36:09 pm by deadly7 »
[17:42:21.609] <Ergot> Kutsuju you're girlfrieds pussy must be a 403 error for you
 [17:42:25.585] <Ergot> FORBIDDEN

on IRC playing T&T++
<iago> He is unarmed
<Hitmen> he has no arms?!

on AIM with a drunk mythix:
(00:50:05) Mythix: Deadly
(00:50:11) Mythix: I'm going to fuck that red dot out of your head.
(00:50:15) Mythix: with my nine

Offline Sidoh

  • Moderator
  • Hero Member
  • *****
  • Posts: 17634
  • MHNATY ~~~~~
    • View Profile
    • sidoh
Re: [PHP]blocking ip address from viewing site
« Reply #1 on: August 05, 2005, 10:13:29 pm »
That's kind of eww-y code as it is. Here's a cleaned up version:


<?php

	
/**
	
* @return string
	
* @desc Searches for the enduser's IP-Address
	
*/
	
function 
get_ipaddr() {
	
	
	
	

	
	
if (
getenv("HTTP_CLIENT_IP") && strcasecmp(getenv("HTTP_CLIENT_IP"), "unknown"))
	
	
	
$ip getenv("HTTP_CLIENT_IP");
	
	
else if (
getenv("HTTP_X_FORWARDED_FOR") && strcasecmp(getenv("HTTP_X_FORWARDED_FOR"), "unknown"))
	
	
	
$ip getenv("HTTP_X_FORWARDED_FOR");
	
	
else if (
getenv("REMOTE_ADDR") && strcasecmp(getenv("REMOTE_ADDR"), "unknown"))
	
	
	
$ip getenv("REMOTE_ADDR");
	
	
else if (isset(
$_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR'] && strcasecmp($_SERVER['REMOTE_ADDR'], "unknown"))
	
	
	
$ip $_SERVER['REMOTE_ADDR'];
	
	
else
	
	
	
$ip "unknown";
	
	
	

	
	
	

	
	
return 
$ip;
	
}
	

	
$ip get_ipaddr();
	
$b_ip = array(
	
	
'127.0.0.1',
	
	
'64.233.167.99'
	
);
	

	
foreach(
$b_ip as $v) {
	
	

	
	
if(
$v == $ip)
	

	
	
	
header('location: www.google.com');
	
	

	
}
	

?>


By the way, the problem with your code is that 127.0.0.1 is a string. You didn't enclose it in quotes. Also -- PHP is pretty leniant on it's syntaxing, but I'm pretty sure it requires you to enclose if statements in parenthensies. Plus, you used "Then" and "{" looks like you were trying to merge VB6 and PHP. :)

Offline deadly7

  • 42
  • Moderator
  • Hero Member
  • *****
  • Posts: 6496
    • View Profile
Re: [PHP]blocking ip address from viewing site
« Reply #2 on: August 05, 2005, 10:33:58 pm »
Care to explain what that does? I've never used them before, and PHP.Net sucks at explaining things.
Quote
Quote
« Last Edit: August 06, 2005, 02:07:45 pm by Sidoh »
[17:42:21.609] <Ergot> Kutsuju you're girlfrieds pussy must be a 403 error for you
 [17:42:25.585] <Ergot> FORBIDDEN

on IRC playing T&T++
<iago> He is unarmed
<Hitmen> he has no arms?!

on AIM with a drunk mythix:
(00:50:05) Mythix: Deadly
(00:50:11) Mythix: I'm going to fuck that red dot out of your head.
(00:50:15) Mythix: with my nine

Offline Warrior

  • supreme mac daddy of trolls
  • Hero Member
  • *****
  • Posts: 7503
  • One for a Dime two for a Quarter!
    • View Profile
Re: [PHP]blocking ip address from viewing site
« Reply #3 on: August 06, 2005, 01:38:25 am »
What the code does is it performs various checks to set an IP then uses a
for each to loop through the  array comparing it and forwarding them to google.com if they
match the list.

The exact methods he used can be found on php.net by searching: getenv();
One must ask oneself: "do I will trolling to become a universal law?" And then when one realizes "yes, I do will it to be such," one feels completely justified.
-- from Groundwork for the Metaphysics of Trolling

Offline rabbit

  • x86
  • Hero Member
  • *****
  • Posts: 8092
  • I speak for the entire clan (except Joe)
    • View Profile
Re: [PHP]blocking ip address from viewing site
« Reply #4 on: August 06, 2005, 02:20:21 am »
<?php
include "nav.html";
print 
"<font color=\"white\">"$_SERVER['REMOTE_ADDR'] ."</font>";
if 
$_SERVER['REMOTE_ADDR'] = 127.0.0.1 Then {
echo 
"<meta http-equiv=\"refresh\" content=\"5; url=http://www.mysite.com/dir/noview.php\" />" }
?>


Why doesn't it work?

Edit: Returns this message
Parse error: parse error, unexpected T_VARIABLE, expecting '(' in /home/deadly7/public_html/ on line 15
Quote
if $_SERVER['REMOTE_ADDR'] = 127.0.0.1 Then {
That is line 15.
Because that's not valid PHP!

<?php
    
include("nav.html");
    echo 
"<font color=\"white\">" $_SERVER['REMOTE_ADDR'] . "</font>";
    if(
$_SERVER['REMOTE_ADDR'] = '127.0.0.1')
    {
        echo 
"<meta http-equiv=\"refresh\" content=\"5; url=http://www.mysite.com/dir/noview.php\" />";
    }
?>

Offline Sidoh

  • Moderator
  • Hero Member
  • *****
  • Posts: 17634
  • MHNATY ~~~~~
    • View Profile
    • sidoh
Re: [PHP]blocking ip address from viewing site
« Reply #5 on: August 06, 2005, 01:06:13 pm »
* Sidoh gives a golfclap for warrior.
Very good! >_>

I already commented on why his code was invalid, rabbit. :P

Why do you weirdos use double-quotes when you're echo'ing html that uses double quotes for attributes? Make more work for yourself... freaks -_-

BTW, Rabbit. You missed something.

if($_SERVER['REMOTE_ADDR'] = '127.0.0.1')

Should be:

if($_SERVER['REMOTE_ADDR'] == '127.0.0.1')
« Last Edit: August 06, 2005, 01:49:35 pm by Sidoh »

Offline deadly7

  • 42
  • Moderator
  • Hero Member
  • *****
  • Posts: 6496
    • View Profile
Re: [PHP]blocking ip address from viewing site
« Reply #6 on: August 06, 2005, 01:30:11 pm »
Code: [Select]
$b_ip = array(
'i.put.my.ip.here',
);

It didn't redirect me to googley. :(
[17:42:21.609] <Ergot> Kutsuju you're girlfrieds pussy must be a 403 error for you
 [17:42:25.585] <Ergot> FORBIDDEN

on IRC playing T&T++
<iago> He is unarmed
<Hitmen> he has no arms?!

on AIM with a drunk mythix:
(00:50:05) Mythix: Deadly
(00:50:11) Mythix: I'm going to fuck that red dot out of your head.
(00:50:15) Mythix: with my nine

Offline Sidoh

  • Moderator
  • Hero Member
  • *****
  • Posts: 17634
  • MHNATY ~~~~~
    • View Profile
    • sidoh
Re: [PHP]blocking ip address from viewing site
« Reply #7 on: August 06, 2005, 01:49:53 pm »
Where'd you obtain your IP Address from?

Offline deadly7

  • 42
  • Moderator
  • Hero Member
  • *****
  • Posts: 6496
    • View Profile
Re: [PHP]blocking ip address from viewing site
« Reply #8 on: August 06, 2005, 02:02:18 pm »
www.whatismyip.com , here (I'm a mod and it shows my IP) , sb.net , and dota-allstars.com
Generally if 4/4 websites tell you that your ip address is what you thought it was, it's probably right.
No I don't run Firefox on any proxies or anything.
[17:42:21.609] <Ergot> Kutsuju you're girlfrieds pussy must be a 403 error for you
 [17:42:25.585] <Ergot> FORBIDDEN

on IRC playing T&T++
<iago> He is unarmed
<Hitmen> he has no arms?!

on AIM with a drunk mythix:
(00:50:05) Mythix: Deadly
(00:50:11) Mythix: I'm going to fuck that red dot out of your head.
(00:50:15) Mythix: with my nine

Offline Sidoh

  • Moderator
  • Hero Member
  • *****
  • Posts: 17634
  • MHNATY ~~~~~
    • View Profile
    • sidoh
Re: [PHP]blocking ip address from viewing site
« Reply #9 on: August 06, 2005, 02:07:05 pm »
I've known people that think they can obtain their public IP address by using ipconfig:

Code: [Select]
Ethernet adapter Local Area Connection:

        Connection-specific DNS Suffix  . :
        IP Address. . . . . . . . . . . . : 10.0.0.4
        Subnet Mask . . . . . . . . . . . : 255.255.255.0
        Default Gateway . . . . . . . . . : 10.0.0.2

Which is why I asked.

Anyway, use debugging. Make the routine echo the ip address it resolved and see if it matches with yours.

Offline deadly7

  • 42
  • Moderator
  • Hero Member
  • *****
  • Posts: 6496
    • View Profile
Re: [PHP]blocking ip address from viewing site
« Reply #10 on: August 06, 2005, 02:11:48 pm »
Quote
24.163.230.126
Warning: Cannot modify header information - headers already sent by (output started at /home/deadly7/public_html/index.php:6) in /home/deadly7/public_html/bp/index.php on line 44
Let me find line 44..

         header('location: www.google.com');
that is line44
« Last Edit: August 06, 2005, 02:13:48 pm by deadly7 »
[17:42:21.609] <Ergot> Kutsuju you're girlfrieds pussy must be a 403 error for you
 [17:42:25.585] <Ergot> FORBIDDEN

on IRC playing T&T++
<iago> He is unarmed
<Hitmen> he has no arms?!

on AIM with a drunk mythix:
(00:50:05) Mythix: Deadly
(00:50:11) Mythix: I'm going to fuck that red dot out of your head.
(00:50:15) Mythix: with my nine

Offline Sidoh

  • Moderator
  • Hero Member
  • *****
  • Posts: 17634
  • MHNATY ~~~~~
    • View Profile
    • sidoh
Re: [PHP]blocking ip address from viewing site
« Reply #11 on: August 06, 2005, 02:30:24 pm »
That's a strange "feature" of PHP I've encountered a few times myself. Try changing it to:

header('location: www.google.com'false);

Offline deadly7

  • 42
  • Moderator
  • Hero Member
  • *****
  • Posts: 6496
    • View Profile
Re: [PHP]blocking ip address from viewing site
« Reply #12 on: August 06, 2005, 02:55:37 pm »
Same error even though I changed the line.
[17:42:21.609] <Ergot> Kutsuju you're girlfrieds pussy must be a 403 error for you
 [17:42:25.585] <Ergot> FORBIDDEN

on IRC playing T&T++
<iago> He is unarmed
<Hitmen> he has no arms?!

on AIM with a drunk mythix:
(00:50:05) Mythix: Deadly
(00:50:11) Mythix: I'm going to fuck that red dot out of your head.
(00:50:15) Mythix: with my nine

Offline Sidoh

  • Moderator
  • Hero Member
  • *****
  • Posts: 17634
  • MHNATY ~~~~~
    • View Profile
    • sidoh
Re: [PHP]blocking ip address from viewing site
« Reply #13 on: August 06, 2005, 02:59:02 pm »
Odd. I have yet to figure out why it does that on some servers. Probably something in php.ini. Just use that meta tag.

Code: [Select]
echo '<meta http-equiv="refresh" content="0; URL=www.google.com" />';

Offline deadly7

  • 42
  • Moderator
  • Hero Member
  • *****
  • Posts: 6496
    • View Profile
Re: [PHP]blocking ip address from viewing site
« Reply #14 on: August 06, 2005, 04:36:56 pm »
OMFG I LOVE YOU SIDOH.
[17:42:21.609] <Ergot> Kutsuju you're girlfrieds pussy must be a 403 error for you
 [17:42:25.585] <Ergot> FORBIDDEN

on IRC playing T&T++
<iago> He is unarmed
<Hitmen> he has no arms?!

on AIM with a drunk mythix:
(00:50:05) Mythix: Deadly
(00:50:11) Mythix: I'm going to fuck that red dot out of your head.
(00:50:15) Mythix: with my nine