Connecting Tech Pros Worldwide Help | Site Map

Header

AJ
Guest
 
Posts: n/a
#1: Jul 17 '05
hi all

I'm having trouble getting something simple working and can't see why.

This is the code I'm running:

<?php if ($row_Recordset1['type']=="agent"){

header("Location: agentindex.php");
echo "AGENT";
exit;
}

else
{
header("Location: llindex.php");
echo "LANDLORD";
exit;
}

?>
Andy Barfield
Guest
 
Posts: n/a
#2: Jul 17 '05

re: Header


AJ wrote:[color=blue]
> I'm having trouble getting something simple working and can't see why.[/color]
Are you getting errors? If so, what are they?
[color=blue]
> header("Location: agentindex.php");[/color]
This will force most browsers to redirect immediately. You should also
specify the full URI, rather than the file name alone.
[color=blue]
> echo "AGENT";[/color]
This may never be executed, or rather may never be seen inthe browser as
it will be replaced with the page to which you have just redirected.
[color=blue]
> header("Location: llindex.php");
> echo "LANDLORD";[/color]
Likewise

If you are getting headers already sent errors, you script is outputting
something before the location call (even one white space character).

Check the manual for Output control and for headers:
http://uk2.php.net/manual/en/ref.outcontrol.php
http://uk2.php.net/header

Hope this helps, regards,

Andy
AJ
Guest
 
Posts: n/a
#3: Jul 17 '05

re: Header



"Andy Barfield" <abarfield_01@yahoo.com> wrote in message
news:q6-dnSZ35eGYK43cRVn-pQ@nildram.net...[color=blue]
> AJ wrote:[color=green]
> > I'm having trouble getting something simple working and can't see why.[/color]
> Are you getting errors? If so, what are they?[/color]

I've actually managed to sort it. I've found two things to watch out for:

1. Probably obvious, but it wasn't to me. I'd put the PHP with the header
information inside the <BODY> of the page
2. It would appear that any white space after the header call messes things
up. Even a space after the ; will cause it not to work

Does that sound feasible?

Andy


Andy Barfield
Guest
 
Posts: n/a
#4: Jul 17 '05

re: Header


Sorry - been away for a couple of days, didn't see your reply.

AJ wrote:[color=blue]
> 1. Probably obvious, but it wasn't to me. I'd put the PHP with the header
> information inside the <BODY> of the page[/color]
Yep, that would do it - the headers must be sent before any other output
to the browser, even a space before the <?php tag will stop it working
and give you a "headers already sent" error.
[color=blue]
> 2. It would appear that any white space after the header call messes things
> up. Even a space after the ; will cause it not to work[/color]
Not seen that happen before. I often use the Location header in an
if-else block like

if(!something)
{
header("Location: http://somewhere.else/");
exit;
}
else
{
echo "I have not reditected you";
}

Regards,

Andy
Closed Thread