lonewolf217 Posted June 17, 2008 Share Posted June 17, 2008 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 https://forums.phpfreaks.com/topic/110515-solved-any-way-in-php-to-redirect-users-automatically-to-another-page/ Share on other sites More sharing options...
trq Posted June 17, 2008 Share Posted June 17, 2008 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 https://forums.phpfreaks.com/topic/110515-solved-any-way-in-php-to-redirect-users-automatically-to-another-page/#findComment-566965 Share on other sites More sharing options...
DarkWater Posted June 17, 2008 Share Posted June 17, 2008 You can try using meta redirects if you want to show them a message, but otherwise, just put the header calls in the appropriate place. Link to comment https://forums.phpfreaks.com/topic/110515-solved-any-way-in-php-to-redirect-users-automatically-to-another-page/#findComment-567023 Share on other sites More sharing options...
lonewolf217 Posted June 17, 2008 Author Share Posted June 17, 2008 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 https://forums.phpfreaks.com/topic/110515-solved-any-way-in-php-to-redirect-users-automatically-to-another-page/#findComment-567186 Share on other sites More sharing options...
jesushax Posted June 17, 2008 Share Posted June 17, 2008 yeah thats right Link to comment https://forums.phpfreaks.com/topic/110515-solved-any-way-in-php-to-redirect-users-automatically-to-another-page/#findComment-567187 Share on other sites More sharing options...
lonewolf217 Posted June 17, 2008 Author Share Posted June 17, 2008 thanks, I was able to get it working perfectly! Link to comment https://forums.phpfreaks.com/topic/110515-solved-any-way-in-php-to-redirect-users-automatically-to-another-page/#findComment-567209 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.