Forum Moderators: coopster

Message Too Old, No Replies

PHP redirect not working

         

too much information

5:51 am on Apr 4, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This is a strange problem, I have a problem with redirecting using

header("location:page.php?ID=".$ID);

but it works fine in another script (a login script) that I have created.

The only thing the script does is insert data into a database (which works) and it should redirect the user back to a listing of the contents of the database.

The version that works uses an IF statement to verify the login against data in the database then redirects depending on the result.

Is there a reason that a redirect wouldn't work at the end of a script? Should I create an IF statement or something? I'm getting confused here.

Habtom

8:00 am on Apr 4, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I hate the errors which comes due to some reason from header. But the most common one is mentioning the header has been sent.

Could you be facing this? If you do, you can make sure you don't have spaces, echos or any kind of output before the header.

habtom

coopster

12:10 pm on Apr 4, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Are you getting errors? A blank page? What is happening?

eeek

12:51 pm on Apr 4, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



header("location:page.php?ID=".$ID);

First of it's "Location: " not "location:"

Secondly, while most browsers may work ok the spec says you have to use a full URL including the domain.

eeek

12:53 pm on Apr 4, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Is there a reason that a redirect wouldn't work at the end of a script?

Headers have to be set before you output anything. They'll only work at the end of a script if the script has not sent anything else.

too much information

2:52 pm on Apr 4, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



All I'm getting is a blank page.

The script doesn't output anything, all it does is take data from a form, add it to my database and redirect the user back to the correct page.

I tried "Location" verses "location" and neither one is working.

Ok, I found the problem. I had an include that was outputing some Javascript and with that gone it works fine.

Thanks for the help!