Page 1 of 1
auto redirect
Posted: Wed Dec 17, 2003 5:01 am
by gecko
i am using the mail function. if the used does not put in anything for the email address, i want the user to be redirected to an other url.
i am using this:
<?php
if ($email="") header("location:
http://www.otherurl.com");
?>
it does not seem to be working. any idea what i am doing wrong.
thanks hans
Posted: Wed Dec 17, 2003 6:47 am
by qads
try:
Code: Select all
<?php
if(empty($email))
{
header("location: url here");
}
?>
if $email is a value from a form field then you need to use $_POST['email'].
Posted: Wed Dec 17, 2003 6:50 am
by patrikG
Code: Select all
<?php
if ($email=="")
header("location: http://www.otherurl.com");
?>
Note the "==" which is a comparison. A single "=" is a value-assignment.
Posted: Wed Dec 17, 2003 7:20 am
by gecko
i am getting the following error:
Warning: Cannot modify header information - headers already sent by (output started at /mail.php:2) in mail.php on line 7
what could this be?
Posted: Wed Dec 17, 2003 7:23 am
by patrikG
if there is any output before you use [php_man]header[/php_man], it won't work.
e.g.
Code: Select all
<?php
echo "Thanks for registering, dude.";
header ("location: http://forums.devnetwork.net");
?>
Will give you the same error, while if you remove the first line ("echo ...") it will work.
Posted: Wed Dec 17, 2003 8:09 am
by pelegk2
AND WRITE Location and not location
Posted: Wed Dec 17, 2003 10:12 am
by gecko
i now have this:
if ($email=="") header ("Location:
http://www.whatever.com");
but nothing happens.
any ideas?
thanks
Posted: Wed Dec 17, 2003 10:18 am
by Draco_03
by the way you always can echo a meta....
just so you know
Code: Select all
<meta http-equiv="refresh" content="0; url=whatever.php" />
Posted: Wed Dec 17, 2003 10:19 am
by Draco_03
qads wrote:try:
Code: Select all
<?php
if(empty($email))
{
header("location: url here");
}
?>
Should try this technique