<?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
Quoteif $_SERVER['REMOTE_ADDR'] = 127.0.0.1 Then {
That is line 15.
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. :)
Care to explain what that does? I've never used them before, and PHP.Net sucks at explaining things.
Quote
Quote
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();
Quote from: deadly7 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
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\" />";
}
?>
/me 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')
$b_ip = array(
'i.put.my.ip.here',
);
It didn't redirect me to googley. :(
Where'd you obtain your IP Address from?
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.
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.
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
That's a strange "feature" of PHP I've encountered a few times myself. Try changing it to:
header('location: www.google.com', false);
Same error even though I changed the line.
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" />';
OMFG I LOVE YOU SIDOH.
Glad I could help. =)
Oh, I should add something...
echo '<meta http-equiv="refresh" content="0; URL=www.google.com" />';
If you're using that, add http:// before the website (www.google.com) or else it will redirect to www.mysite.com/folder/www.google.com
Well, yeah. That was um... shorthand HTML. *looks around nervously*
The reason the header didn't work: If you're going to do something like that you need to make sure it's one of the first things done, else the page will already have sent it's header information out thus producing that error.
war, so I should've put that before <head>?
No.
<head>
<meta http-equiv="refresh" content="5; url=refresh1.html">
<title> chapter 17 multimedia </title>
</head>
works just as well.
Quote from: Anti-Newby on August 06, 2005, 11:44:42 PM
The reason the header didn't work: If you're going to do something like that you need to make sure it's one of the first things done, else the page will already have sent it's header information out thus producing that error.
It always works unless you've done anything with sessions or cookies (I'm sure there are other similar causes of the error, but these are the two main cuprates I've found).
And no, deadly7. He's saying it's the first routine that should be executed within PHP.
By tradition, meta tags are within the head tags, but it doesn't matter (I think W3C might care, but all browsers I use don't).
First or near first, from what I've noticed.
Quote from: Anti-Newby on August 07, 2005, 10:32:01 AM
First or near first, from what I've noticed.
Anything that is before a session or cookie declaration is my belief.
PERHAPS AN INVESTIGATION !
Rather than looping through the array. Which, works just fine. Using in_array() would be a bit faster.
if (in_array($ip, $iparray)) {
die('You are banned!');
}
Haha, yeah. I just remembered that function a few days ago when I was doing something with arrays.
Good to see ya venox! :)
Quote from: Sidoh on August 23, 2005, 07:44:36 PM
Haha, yeah. I just remembered that function a few days ago when I was doing something with arrays.
Good to see ya venox! :)
Likewise :)
Note that given things like HTTP_X_FORWARDED_FOR are headers sent by the client they can be forged and as such checking only them is likely a bad idea. One should really be checking all possible ips and not just the first found one.
Quote from: zorm on August 23, 2005, 10:46:29 PM
Note that given things like HTTP_X_FORWARDED_FOR are headers sent by the client they can be forged and as such checking only them is likely a bad idea. One should really be checking all possible ips and not just the first found one.
Blame the guy on php.net! :)
I'll blame you for not knowing better yet selling your PHP services! :p
I just remembered that it was there and copied/pasted from it. =P
It's better than getenv("REMOTE_ADDR").
I did know that, by the way. :-\
"selling my services?" Show me the price, please.
Mine is $40/hour (http://liquid-dev.org/)
I don't think anyone was asking anything near the subject of a specific price on PHP development. Plus, zorm's statement wasn't even directed towards you.
Eh..he said "show me the price". Close enough.
Quote from: deadly7 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
Quoteif $_SERVER['REMOTE_ADDR'] = 127.0.0.1 Then {
That is line 15.
Although this has been resolved; Mark since you're using a Boolean, try to put the include statement on the return true section of the script, I.E.
<?php
if($_SERVER['REMOTE_ADDR'] == "127.0.0.1")
{ ?>
<meta http-equiv="refresh" content="5; url=noview.php">
<?php
} else {
include "nav.html";
}
?>
It's easier to just include some file that checks for banned IP's and then uses exit; if it finds one.
Yeah, using the .htaccess or on a dedicated linux build, use SSH to modify the access.conf file using DenyAll
Quote from: subject[PHP]blocking ip address from viewing site
Which is why I didn't include information in .htaccess. :)
Jeesh your hard to counterpoint :P
Hehe.