SCook Posted August 24, 2006 Share Posted August 24, 2006 Hi gang,I've got a couple of ideas, but maybe there's a simple solutions out there. My problem is that I have a page that needs to redirect once the php has been exectured. Now, the problem is that this page is built using require() for the header and footer portions. So the middle part, the actuall page, executes the code and then has to go back to the home page. Now, if I use header(), it fails because the header.php which is required, already exists, and therefore throws an exception.So, is there another redirect function, or am I going to have to get creative? Link to comment https://forums.phpfreaks.com/topic/18558-page-redirects-without-using-header/ Share on other sites More sharing options...
.josh Posted August 24, 2006 Share Posted August 24, 2006 this is probably a dumb solution, but how about making a variable in your required header and/or footer .php and then wrapping an if statement around the require function like so:if (!$blah) { require ('header.php');}or am i totally not understanding the situation Link to comment https://forums.phpfreaks.com/topic/18558-page-redirects-without-using-header/#findComment-79931 Share on other sites More sharing options...
wildteen88 Posted August 24, 2006 Share Posted August 24, 2006 header wont fail if you have a file called header.php. It'll only fail if you have some form of out being sent to the browser before the use of the header function.You might want to use ob_start and ob_end_flush to turn on output buffering. Or you can use good old html to redirect. There is not otrher PHP function you can use to redirect the user. header is only option in PHP. Link to comment https://forums.phpfreaks.com/topic/18558-page-redirects-without-using-header/#findComment-79932 Share on other sites More sharing options...
poirot Posted August 24, 2006 Share Posted August 24, 2006 If you are getting an error like "Warning: Cannot modify header information - headers already sent by" read wildteen's post Link to comment https://forums.phpfreaks.com/topic/18558-page-redirects-without-using-header/#findComment-79935 Share on other sites More sharing options...
AdRock Posted August 24, 2006 Share Posted August 24, 2006 I had a similar problem and my solution was to use this[code]echo" <meta http-equiv='refresh' content='3;url=http://www.yoursite.com/index.php'>";[/code]You could chnage the content=3 to however long you like in seconds Link to comment https://forums.phpfreaks.com/topic/18558-page-redirects-without-using-header/#findComment-79949 Share on other sites More sharing options...
onlyican Posted August 24, 2006 Share Posted August 24, 2006 [quote author=AdRock link=topic=105503.msg421499#msg421499 date=1156441668]I had a similar problem and my solution was to use this[code]echo" <meta http-equiv='refresh' content='3;url=http://www.yoursite.com/index.php'>";[/code]You could chnage the content=3 to however long you like in seconds[/quote]I have been told that that meta does not work on IE Link to comment https://forums.phpfreaks.com/topic/18558-page-redirects-without-using-header/#findComment-79952 Share on other sites More sharing options...
AdRock Posted August 24, 2006 Share Posted August 24, 2006 It does for me....works perfectly Link to comment https://forums.phpfreaks.com/topic/18558-page-redirects-without-using-header/#findComment-80108 Share on other sites More sharing options...
hitman6003 Posted August 24, 2006 Share Posted August 24, 2006 You could also use javascript:[code]echo '<script type="text/javascript">window.location.href = "somepage.php";</script>';[/code] Link to comment https://forums.phpfreaks.com/topic/18558-page-redirects-without-using-header/#findComment-80110 Share on other sites More sharing options...
AdRock Posted August 24, 2006 Share Posted August 24, 2006 Would that work if the user has got javascript disabled in their browser? Link to comment https://forums.phpfreaks.com/topic/18558-page-redirects-without-using-header/#findComment-80112 Share on other sites More sharing options...
hitman6003 Posted August 24, 2006 Share Posted August 24, 2006 Would any javascript work if the user has javascript disabled? Link to comment https://forums.phpfreaks.com/topic/18558-page-redirects-without-using-header/#findComment-80114 Share on other sites More sharing options...
wildteen88 Posted August 25, 2006 Share Posted August 25, 2006 If javascript is disabled then the answer is no. Link to comment https://forums.phpfreaks.com/topic/18558-page-redirects-without-using-header/#findComment-80321 Share on other sites More sharing options...
Jenk Posted August 25, 2006 Share Posted August 25, 2006 It's better to redesign your script to send the header()'s before any output. Using output buffering (ob_start/ob_end_flush) does work, but it can be load inducing on the server (all output is stored in memory until flush, instead of direct output to browser)Also, meta tag refresh is more reliable than header('Location: ... '); as surprisingly, more browsers support meta's than do header. (Some browsers also have options to ignore header redirects) Link to comment https://forums.phpfreaks.com/topic/18558-page-redirects-without-using-header/#findComment-80324 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.