View Full Version : need help with re-directing
spezticle
11-17-2004, 05:12 PM
hey there...
was just wondering if anyone knew a simple way to re-direct a user from one page, to another based on their IP or host name.
situation is, i dont want people from a certain host name in particular to be able to access my website for very important reasons... if they try and view the site, based on their hostname or IP addy, it will redirect them to another site.
any help would much be appreciated :) :)
Benjamin
123456789
11-17-2004, 05:19 PM
Warning, this is PHP, so if you host doesn't support it, it won't work.
<?php
if(getenv("REMOTE_ADDR")=='66.156.98.789'){
header("Location: the_redirected_page.html");
}
?>
}
spezticle
11-17-2004, 05:24 PM
my host indeed does support PHP. Thank you very much...
just in case you're wondering...
i've been legally advised that a certain person who access my webpage from their highschool, viewing my website is very bad news for me, so any way possible to keep this person from viewing the page is wonderful :)
thanks again!
123456789
11-17-2004, 07:22 PM
No problem. You can also record people's IP using getenv("REMOTE_ADDR"). You could record it in a text file.
spezticle
11-18-2004, 06:08 PM
what about the getenv tag for getting their host name? is there such?
something like..
getenv("REMOTE_HOST")
?
oh yes, and of course, if you know it off the top of your head, once i've gotten the remote IP and possibly the host name, you said i could write it to a file...
you know what the tag is to write them in a text file, taking for granted i already know that the dir needs to be chmod 777?
123456789
11-19-2004, 03:50 PM
Originally posted by spezticle
what about the getenv tag for getting their host name? is there such?
something like..
getenv("REMOTE_HOST")
?
oh yes, and of course, if you know it off the top of your head, once i've gotten the remote IP and possibly the host name, you said i could write it to a file...
you know what the tag is to write them in a text file, taking for granted i already know that the dir needs to be chmod 777?
What do you mean about host name? Also, for writing to the file, try this (change ip.txt to the file you want to write to):
<?php
$log_file = "ip.txt";
$ip = getenv('REMOTE_ADDR');
$fp = fopen("$log_file", "a");
fputs($fp, "$ip");
flock($fp, 3);
fclose($fp);
?>
123456789
11-19-2004, 04:06 PM
Oh. For the host thing, I'm not sure if this is it, but go to here:
http://htmlforums.com/showthread.php?s=&threadid=49384
vBulletin® v3.6.7, Copyright ©2000-2010, Jelsoft Enterprises Ltd.