Jump to content

Page redirects without using header();


SCook

Recommended Posts

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
Share on other sites

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
Share on other sites

[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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.