Jump to content

[SOLVED] Any way in php to redirect users automatically to another page?


lonewolf217

Recommended Posts

I know there is a way to use a header to automatically redirect as soon as they hit your page, but unfortunetly that is not what I wanted.  I got spoiled with .asp using the Response.Redirect to redirect users back to a particular page after running my background scripts but I cannot figure out a way to do the same with php since I have read that the header must be the ONLY line in the file else it will not work.

 

Is there an exception to this, or is this just the nature of php ?

A call to header() works fine. It just needs to be made before any output which makes perfect sense seeing as outputting something and then redirecting makes no sense at all.

 

The only reason you can get away with the same thing in asp is because of a hack that has your entire output placed within a buffer. This can also be done in php but as I said, it is a hack.

so you are saying as long as I dont output anything I can still use the header redirect later down the page ?  like if I have the PHP script to insert data into the database but I have no echo or print statements, then at the bottom of the script I can have a redirect back to the main page

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.