delphi123 Posted August 25, 2009 Share Posted August 25, 2009 When I'm coding asp/.net I frequently want to redirect users after I've run some code - eg for a news posting system I'd have a form send to an asp page that'd insert to the database and then redirect them back where they were. Can anyone tell me what the command is for php? Have dug around, but most redirects seem to be limited to 301-style execution (ie at top of the page before code) Quote Link to comment https://forums.phpfreaks.com/topic/171809-rediredt-on-form-finish/ Share on other sites More sharing options...
otuatail Posted August 25, 2009 Share Posted August 25, 2009 header('Location: index.php'); for example will send you back to a page. If you need a specific page then you could send it in the url or store the variable in a session. Quote Link to comment https://forums.phpfreaks.com/topic/171809-rediredt-on-form-finish/#findComment-905947 Share on other sites More sharing options...
mikesta707 Posted August 25, 2009 Share Posted August 25, 2009 header is, I guess what you called a 301 style execution. it needs to be executed before any output is sent (IE at the top of the page). Beyond that, I don't think PHP has any other ways to redirect a user. You can use meta tags to redirect a user, as well as javascript, (but both of those can be disabled, so these may want to be avoided). Quote Link to comment https://forums.phpfreaks.com/topic/171809-rediredt-on-form-finish/#findComment-905949 Share on other sites More sharing options...
otuatail Posted August 25, 2009 Share Posted August 25, 2009 Yep this will not work if header is sent. Only way is a submit button or to auto refresh the page after x number of seconds. Quote Link to comment https://forums.phpfreaks.com/topic/171809-rediredt-on-form-finish/#findComment-905962 Share on other sites More sharing options...
delphi123 Posted August 25, 2009 Author Share Posted August 25, 2009 that's strange - so I'd normally have a form on a page that sends the data in post to a 'processing' page which then bounces the user back to the original page. Would you normally use the header option for this? (or is there some other method entirely in php?) Quote Link to comment https://forums.phpfreaks.com/topic/171809-rediredt-on-form-finish/#findComment-906000 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.