Jump to content

Help With Redirect


walapu
 Share

Recommended Posts

I have looked around but I do not seem to understand how lets say I would do a redirect after code. Could someone please explain this? Sorry I am a noob lol. I know that this is supposed to go b4 all code, but how would I lets say make it so when someone presses submit it would send them to another page.echo "blabaabl"header( 'Location: http://www.yoursite.com/new_page.html' ) ;

Edited by walapu
Link to comment
Share on other sites

Is there any other way to do a redirect after you send an output? Wait I dont understand. How would I use a header so I can do it that way? lol you probably think I am an idiot right now. I just started php a few days ago so give me some slack. :)

Edited by walapu
Link to comment
Share on other sites

The code you showed sends the location header, that will redirect. I'm not sure why you want to redirect after sending output, if you're going to redirect anyway there's no reason to send any output, the user would never see it. The technical reason why you can't do that is because as soon as you send any output PHP will automatically send all of the response headers first, so if you try to send another header after that it's going to be an error since the headers were already sent. If you use output buffering then you can send headers at any point because PHP saves all of the output in a buffer and then sends the entire buffer once the script ends.A location header isn't the only way to redirect, you can also use an HTML meta refresh tag to redirect after a set amount of seconds.

Link to comment
Share on other sites

Guest FirefoxRocks

justsomeguy also posted a basic thing about headers at the pinned topic if you want to find more information.http://w3schools.invisionzone.com/index.ph...ost&p=96607And as mentioned above, there is no point in redirecting with output. If you are going to do that then output a link along with whatever output you want and get the user to click on it.

Edited by FirefoxRocks
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...