simpli Posted March 21, 2009 Share Posted March 21, 2009 Hi, I have a form. It was validated, treatment was done data inserted in my db and I want to redirect the user to another page so I use header("http://localhost/showresults.php"); Nothing happens however. In the documentation they say header must be used before anything is output and I'm not sure I understand that. Does that mean that from the moment you have output something in your web page header will not work? Anyhow can someone tell me what I should use to redirect the users to the above page? Thank you, J-R Quote Link to comment https://forums.phpfreaks.com/topic/150509-header-not-working/ Share on other sites More sharing options...
Mchl Posted March 21, 2009 Share Posted March 21, 2009 It's header("Location: http://..."); and no... you can not set headers once any other output has been sent to browser. Quote Link to comment https://forums.phpfreaks.com/topic/150509-header-not-working/#findComment-790520 Share on other sites More sharing options...
jackpf Posted March 21, 2009 Share Posted March 21, 2009 Well, if you use output buffering it sorts it out for you... Quote Link to comment https://forums.phpfreaks.com/topic/150509-header-not-working/#findComment-790542 Share on other sites More sharing options...
Mchl Posted March 21, 2009 Share Posted March 21, 2009 Well, if you use output buffering it sorts it out for you... for a time... Quote Link to comment https://forums.phpfreaks.com/topic/150509-header-not-working/#findComment-790554 Share on other sites More sharing options...
jackpf Posted March 21, 2009 Share Posted March 21, 2009 Ouput buffering does put a bit of an overhead on php generating your page, but it actually speeds up the browser rendering it(depending on how much code there is), and aided with page compression can increase loading times furthermore. So depending on how much code you're sending to the page, OB can actually increase speed. Quote Link to comment https://forums.phpfreaks.com/topic/150509-header-not-working/#findComment-790565 Share on other sites More sharing options...
Mchl Posted March 21, 2009 Share Posted March 21, 2009 This is valid use for output rendering. Using it to defer output so that heading can be send is not so good. It is much better to restructure the code, so that the headers are actually sent before any content (buffered or not). It's not that difficult usually. Quote Link to comment https://forums.phpfreaks.com/topic/150509-header-not-working/#findComment-790570 Share on other sites More sharing options...
jackpf Posted March 21, 2009 Share Posted March 21, 2009 I completely agree. But if you can kill two birds with one stone... Quote Link to comment https://forums.phpfreaks.com/topic/150509-header-not-working/#findComment-790572 Share on other sites More sharing options...
MadTechie Posted March 21, 2009 Share Posted March 21, 2009 instead of killing 2 birds, use a better design to stop the birds and thus saving your stones! LOL Quote Link to comment https://forums.phpfreaks.com/topic/150509-header-not-working/#findComment-790586 Share on other sites More sharing options...
jackpf Posted March 22, 2009 Share Posted March 22, 2009 Lol Well yeah, I guess, but as stated above, it can be beneficial to use output buffering. Quote Link to comment https://forums.phpfreaks.com/topic/150509-header-not-working/#findComment-790615 Share on other sites More sharing options...
simpli Posted March 22, 2009 Author Share Posted March 22, 2009 If I have already sent something to the page is there another function I can use to redirect the user to another page? I'm not sure I understand the usefulness of this function if we cannot use it after stuff has been output to the web page. If for instance I have a validation form that was created through php and then the form is validated ok and I want to write some data and then send it on to the next page. Technically data has been output to the page (The first time when i created the page). So how would/should I go about doing what I wanna do? Thanks for clarifying. J-R Quote Link to comment https://forums.phpfreaks.com/topic/150509-header-not-working/#findComment-790689 Share on other sites More sharing options...
trq Posted March 22, 2009 Share Posted March 22, 2009 I'm not sure I understand the usefulness of this function if we cannot use it after stuff has been output to the web page I don't understand why you would want to output something to the browser if all your going to do is redirect to another page. That makes even less sense. Quote Link to comment https://forums.phpfreaks.com/topic/150509-header-not-working/#findComment-790695 Share on other sites More sharing options...
Mchl Posted March 22, 2009 Share Posted March 22, 2009 If you want to display a message for user, and then redirect after let's say 3 seconds, then use HTML redirect. Headers are not suited for this. Quote Link to comment https://forums.phpfreaks.com/topic/150509-header-not-working/#findComment-790724 Share on other sites More sharing options...
jackpf Posted March 22, 2009 Share Posted March 22, 2009 If you send a header to redirect someone they won't even see the output (provided you're using OB, if you're not it'll just die) so there's no point in attempting what you're suggesting. As Mchl said, if you want a pause, you can use meta tags or javascript. Quote Link to comment https://forums.phpfreaks.com/topic/150509-header-not-working/#findComment-790792 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.