More then one Header Redirection

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
nite4000
Forum Contributor
Posts: 209
Joined: Sun Apr 12, 2009 11:31 am

More then one Header Redirection

Post by nite4000 »

Hey I need to get this form code to work. I need it to redirect a user to a different page according to what they select in the drop box.
Here is the code

Code: Select all

$_SESSION['manual.php'] = true;
 
if (strlen($_POST['go'])) {
 
 
 if ($_POST['paypro'] == 'LR') 
 {
  
 
 $location = "lr_form.php";
 
 }
 
 if ($_POST['paypro'] == 'PM') 
  {
  
 
 $location = "pm_form.php";
 
 
 
 }
 
 
header ("Location: $location");
} else {
  $_SESSION['manual.php'] = false;
}
 
 
I am not sure why it wont work i get a error msgs about cannot send header information

hope someone can help

Thanks
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: More then one Header Redirection

Post by jackpf »

Is there any output before the error message?
nite4000
Forum Contributor
Posts: 209
Joined: Sun Apr 12, 2009 11:31 am

Re: More then one Header Redirection

Post by nite4000 »

what kind of out put? I may not know it as a out put so you will have to give me an example
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: More then one Header Redirection

Post by jackpf »

As in, is there anything on the page before the error message??
nite4000
Forum Contributor
Posts: 209
Joined: Sun Apr 12, 2009 11:31 am

Re: More then one Header Redirection

Post by nite4000 »

no only when i try to execute teh code after pressing the button
User avatar
desperado
Forum Commoner
Posts: 46
Joined: Wed Dec 10, 2008 8:49 am

Re: More then one Header Redirection

Post by desperado »

if there is there *any* whitespace, carriage return, html..... in your file before your script, you will get that error.

Code: Select all

<?php
$_SESSION['manual.php'] = true;
 
if (strlen($_POST['go'])) {
 
 
 if ($_POST['paypro'] == 'LR')
 {
 
 
 $location = "lr_form.php";
 
 }
 
 if ($_POST['paypro'] == 'PM')
  {
 
 
 $location = "pm_form.php";
 
 
 
 }
 
 
header ("Location: $location");
} else {
  $_SESSION['manual.php'] = false;
}
?>
the above would be ok, whereas below is not:

Code: Select all

 
<html>                [color=#80BF40]<--notice this?[/color]
<head>               [color=#80BF40]<--notice this?[/color]
                            [color=#80BF40]<--notice this?[/color]
<?php
$_SESSION['manual.php'] = true;
 
if (strlen($_POST['go'])) {
 
 
 if ($_POST['paypro'] == 'LR')
 {
 
 
 $location = "lr_form.php";
 
 }
 
 if ($_POST['paypro'] == 'PM')
  {
 
 
 $location = "pm_form.php";
 
 
 
 }
 
 
header ("Location: $location");
} else {
  $_SESSION['manual.php'] = false;
}
?>
nite4000
Forum Contributor
Posts: 209
Joined: Sun Apr 12, 2009 11:31 am

Re: More then one Header Redirection

Post by nite4000 »

This is the error when i try it

Warning: Cannot modify header information - headers already sent by (output started at /home/surf/public_html/memheader.php:4) in /home/surf/public_html/members/manual.php on line 35


line 35 is this

Code: Select all

header ("Location: $location");
which is part of

Code: Select all

header ("Location: $location");
} else {
  $_SESSION['manual.php'] = false;
}
 

any ideas?
User avatar
desperado
Forum Commoner
Posts: 46
Joined: Wed Dec 10, 2008 8:49 am

Re: More then one Header Redirection

Post by desperado »

please re-read my previous post above. your script is probably an include within other files, therefore you have something before it is called.
nite4000
Forum Contributor
Posts: 209
Joined: Sun Apr 12, 2009 11:31 am

Re: More then one Header Redirection

Post by nite4000 »

yeah i see what the problem is so there isnt no other way I can have it do what i want without using the header redirection?
User avatar
desperado
Forum Commoner
Posts: 46
Joined: Wed Dec 10, 2008 8:49 am

Re: More then one Header Redirection

Post by desperado »

why not just leave it by itself and have the form target "members/manual.php" directly, instead of the page where it is included?

the redirect will be instantanious, and you'll never notice you were on a page with no header and footer...
Post Reply