[PHP]blocking ip address from viewing site

Started by deadly7, August 05, 2005, 09:33:18 PM

Previous topic - Next topic

0 Members and 2 Guests are viewing this topic.

deadly7

<?phpinclude "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
Quoteif $_SERVER['REMOTE_ADDR'] = 127.0.0.1 Then {
That is line 15.
[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

Sidoh

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. :)

deadly7

#2
Care to explain what that does? I've never used them before, and PHP.Net sucks at explaining things.
Quote
Quote
[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

Warrior

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

rabbit

Quote from: deadly7 on August 05, 2005, 09:33:18 PM
<?phpinclude "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
Quoteif $_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\" />";    }?>

Sidoh

#5
* 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')?>

deadly7

$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

Sidoh


deadly7

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

Sidoh

I've known people that think they can obtain their public IP address by using ipconfig:

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.

deadly7

#10
Quote24.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
[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

Sidoh

That's a strange "feature" of PHP I've encountered a few times myself. Try changing it to:

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

deadly7

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

Sidoh

Odd. I have yet to figure out why it does that on some servers. Probably something in php.ini. Just use that meta tag.


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

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