auto redirect

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

Post Reply
gecko
Forum Commoner
Posts: 34
Joined: Thu Oct 24, 2002 3:45 am

auto redirect

Post 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
qads
DevNet Resident
Posts: 1199
Joined: Tue Apr 23, 2002 10:02 am
Location: Brisbane

Post 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'].
User avatar
patrikG
DevNet Master
Posts: 4235
Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK

Post 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.
gecko
Forum Commoner
Posts: 34
Joined: Thu Oct 24, 2002 3:45 am

Post 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?
User avatar
patrikG
DevNet Master
Posts: 4235
Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK

Post 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.
User avatar
pelegk2
Forum Regular
Posts: 633
Joined: Thu Nov 27, 2003 5:02 am
Location: Israel - the best place to live in after heaven
Contact:

Post by pelegk2 »

AND WRITE Location and not location
gecko
Forum Commoner
Posts: 34
Joined: Thu Oct 24, 2002 3:45 am

Post by gecko »

i now have this:

if ($email=="") header ("Location: http://www.whatever.com");

but nothing happens.

any ideas?

thanks
Draco_03
Forum Regular
Posts: 577
Joined: Fri Aug 15, 2003 12:25 pm
Location: Montreal, Canada

Post 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" />
Draco_03
Forum Regular
Posts: 577
Joined: Fri Aug 15, 2003 12:25 pm
Location: Montreal, Canada

Post by Draco_03 »

qads wrote:try:

Code: Select all

<?php
if(empty($email))
{
header("location: url here");
}
?>
Should try this technique
Post Reply