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 ?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.