Click to See Complete Forum and Search --> : Redirect a specific IP address to a specific file


towerboy
05-14-2005, 11:11 PM
Hi all,

I have looked everywhere and have not found the right solution for what I want to do.

This is what I need to do.
The guy (Chris) who owns some-domain.com just got the job of his dreams and a friend (Dave) of ours want to do something funny with Chris’s site. Dave and I do all the design for it so it is not a problem. I made a flash movie and want only Chris to see it when he goes to the site.

Is there any wany to use PHP to get his IP address (yes I know his IP) and then redirect only him to another page in the same directory?

If it can’t be done with PHP, does anyone know a way that it could be done? Like I said, I have looked all over and it doesn’t seem anyone has done exactly what I want to do. Thanks for your help.

grailquester5
05-15-2005, 12:23 AM
If you know his IP address (as you do), try:


$addr = $REMOTE_ADDR;

if ($addr == 123.456.78.90) {
header('Location: http://the.url.com/thedir/the_flash_page.php');
}

Where '123.456.78.90' is the URL of your friend and 'the.url.com/thedir/the_flash_page.php' is the place you want that IP address to land.

towerboy
05-15-2005, 12:38 AM
grailquester5,


I am brand new to php so you are going to have to tell me exactly where to place this code. Also, is that all the code? Do I need any start or end tags? What are they? Thanks........

I found that I think I need to use "<?php your stuff ?>
I get this error though:

Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/index.php:5) in /var/www/html/index.php on line 24

The file is http://www.rvla.org/index.php if that is of any help to see what I did. Thanks...........

SpectreReturns
05-15-2005, 03:05 AM
If you know his IP address (as you do), try:


$addr = $REMOTE_ADDR;

if ($addr == 123.456.78.90) {
header('Location: http://the.url.com/thedir/the_flash_page.php');
}

Where '123.456.78.90' is the URL of your friend and 'the.url.com/thedir/the_flash_page.php' is the place you want that IP address to land.

Use this instead, as register globals may be turned off.


$addr = $_ENV['REMOTE_ADDR'];

if ($addr == 123.456.78.90) {
header('Location: http://the.url.com/thedir/the_flash_page.php');
}


Also, that error means that you have something before the <?php tag. Headers need to come before anythign at all on the page, or else you get that error.

towerboy
05-16-2005, 08:50 AM
Well, I tried both pieces of php and niether seem to do the job. I get another error:
Parse error: parse error in /var/www/html/redirect.php on line 5

The only thing I changed was the ip address to mine for testing purposes. You can view the document here (http://www.towerboy.com/redirect.php). I am doing the testing on my domain instead of his.

towerboy
05-16-2005, 09:25 AM
Success!!!!

I was looking through the code that SpectreReturns posted and decided to try putting single quotes around the ip address in the "if" line. It works.

<?php

$addr = $_ENV['REMOTE_ADDR'];

if ($addr == '12.73.24.22') {
header('Location: http://www.thedomain.com/file.whatever');
}

?>

Thanks to all who helped.