PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
redhair
Forum Contributor
Posts: 300 Joined: Fri May 30, 2003 4:36 pm
Location: 53.23N-6.57E
Contact:
Post
by redhair » Fri Feb 20, 2004 7:22 pm
popcop wrote: aaargggghhhh..... i cant get this to work
Are you running php at all?
Try this code, and tell me if it works:
Code: Select all
<?php
$ip = getenv("REMOTE_ADDR");
echo $ip;
?>
Do you see your ip when you run this?
dethron
Forum Contributor
Posts: 370 Joined: Sat Apr 27, 2002 11:39 am
Location: Istanbul
Post
by dethron » Fri Feb 20, 2004 7:22 pm
Just write the following to a blank page, then save it.
And request this file server via browser.
Code: Select all
<script>location.replace('http://www.borsacini.com')</script>
Does it work?
If not, we should search other things to find the problem; because there is nothing wrong with this code-line.
(!!dont forget browser compatibility, i didnt checkhed which of those supports location.replace)
By the way, what is your browser?
dethron
Forum Contributor
Posts: 370 Joined: Sat Apr 27, 2002 11:39 am
Location: Istanbul
Post
by dethron » Fri Feb 20, 2004 7:27 pm
By the way compatibility for window.location.replace is
IE 4.0+, NS 4.0+, Mac/Win
redhair
Forum Contributor
Posts: 300 Joined: Fri May 30, 2003 4:36 pm
Location: 53.23N-6.57E
Contact:
Post
by redhair » Fri Feb 20, 2004 7:29 pm
Why not use header
Code: Select all
<?php
header ("location:http://www.php.net");
?>
Works with all browsers.
dethron
Forum Contributor
Posts: 370 Joined: Sat Apr 27, 2002 11:39 am
Location: Istanbul
Post
by dethron » Fri Feb 20, 2004 7:31 pm
Yes redhair, it is possible too.
Actually, considering bc(browser compatibility), your suggestion is better.
redhair
Forum Contributor
Posts: 300 Joined: Fri May 30, 2003 4:36 pm
Location: 53.23N-6.57E
Contact:
Post
by redhair » Fri Feb 20, 2004 7:41 pm
considering cs(common sence) I would just use
this . Posted earlier in this topic.
But popcop says 'it doesnt ~seem~ to be working',....
popcop
Forum Newbie
Posts: 21 Joined: Fri Jan 30, 2004 10:42 am
Post
by popcop » Fri Feb 20, 2004 7:45 pm
xcxc
Last edited by
popcop on Fri Feb 20, 2004 8:01 pm, edited 2 times in total.
dethron
Forum Contributor
Posts: 370 Joined: Sat Apr 27, 2002 11:39 am
Location: Istanbul
Post
by dethron » Fri Feb 20, 2004 7:45 pm
Since location.replace is works for me until now, I haven't complain about it
)
But now, I found a better substitude for location.replace considering both cs and bc
Thnx.
dethron
Forum Contributor
Posts: 370 Joined: Sat Apr 27, 2002 11:39 am
Location: Istanbul
Post
by dethron » Fri Feb 20, 2004 7:54 pm
Since it works for simple code. It must also work for the complex code except the complex code has another problem.
Add a line that echos the $REMOTE_ADDR
What is the remote address? Are you sure it is 62.252.128.12
popcop
Forum Newbie
Posts: 21 Joined: Fri Jan 30, 2004 10:42 am
Post
by popcop » Fri Feb 20, 2004 7:56 pm
yeah i was testin it on myself to see if would work but it never
dethron
Forum Contributor
Posts: 370 Joined: Sat Apr 27, 2002 11:39 am
Location: Istanbul
Post
by dethron » Fri Feb 20, 2004 8:00 pm
Code: Select all
<?php
echo "<html><head><title>Untitled Document</title></head> ";
echo "<body>";
$ip = "62.252.128.12";
if($REMOTE_ADDR == $ip) {
echo "red queen";
}
echo "</body></html> ";
?>
Try this code, did you see the red queen?
d3ad1ysp0rk
Forum Donator
Posts: 1661 Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA
Post
by d3ad1ysp0rk » Fri Feb 20, 2004 8:02 pm
dethron, your code will only work if register globals is on..
dethron
Forum Contributor
Posts: 370 Joined: Sat Apr 27, 2002 11:39 am
Location: Istanbul
Post
by dethron » Fri Feb 20, 2004 8:04 pm
Then add a line to my code
Code: Select all
<?php
//I am assuming the register global is on
?>
Thnx for correction.
evilMind
Forum Contributor
Posts: 145 Joined: Fri Sep 19, 2003 10:09 am
Location: Earth
Post
by evilMind » Fri Feb 20, 2004 9:47 pm
The reason why it's not working is because you have sent the headers already (when you opened output to the client)
Try this. Move ALL of the php code before ANY HTML output. In fact, make sure that there is no output sent to the client before you try to use the header function (*note* blank lines at the end of a file can cause headers to be sent).
eg:
Code: Select all
<html>
<head><title>Foo</title></head>
<body>
<?php
if ($_SERVERї'REMOTE_ADDR'] == '127.0.0.1') {
header('Location: http://www.foo.com/');
exit(0);
}
?>
<!-- This will NOT work -->
</body>
</html>
but....
Code: Select all
<?php
if ($_SERVERї'REMOTE_ADDR'] == '127.0.0.1') {
header('Location: http://www.foo.com/');
exit(0);
}
?>
<html>
<head><title>Foo</title></head>
<body>
Hi :)
<!-- This WILL work -->
</body>
</html>