Jump to content


Photo

Page redirects without using header();


  • Please log in to reply
11 replies to this topic

#1 SCook

SCook
  • Members
  • PipPipPip
  • Advanced Member
  • 73 posts

Posted 24 August 2006 - 05:04 PM

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?

#2 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 24 August 2006 - 05:14 PM

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
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#3 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 24 August 2006 - 05:15 PM

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.

#4 poirot

poirot
  • Members
  • PipPipPip
  • Advanced Member
  • 646 posts
  • LocationAustin, TX

Posted 24 August 2006 - 05:22 PM

If you are getting an error like "Warning: Cannot modify header information - headers already sent by" read wildteen's post
~ D Kuang

#5 AdRock

AdRock
  • Members
  • PipPipPip
  • Advanced Member
  • 911 posts

Posted 24 August 2006 - 05:47 PM

I had a similar problem and my solution was to use this

echo" <meta http-equiv='refresh' content='3;url=http://www.yoursite.com/index.php'>";

You could chnage the content=3 to however long you like in seconds
If your topic has been solved, please mark the topic as SOLVED.

This helps others from identifying which topics need help still

#6 onlyican

onlyican
  • Members
  • PipPipPip
  • Advanced Member
  • 921 posts
  • LocationHants - UK

Posted 24 August 2006 - 05:52 PM

I had a similar problem and my solution was to use this

echo" <meta http-equiv='refresh' content='3;url=http://www.yoursite.com/index.php'>";

You could chnage the content=3 to however long you like in seconds


I have been told that that meta does not work on IE

Tell me the problem, I will try tell you the solution

#7 AdRock

AdRock
  • Members
  • PipPipPip
  • Advanced Member
  • 911 posts

Posted 24 August 2006 - 11:44 PM

It does for me....works perfectly
If your topic has been solved, please mark the topic as SOLVED.

This helps others from identifying which topics need help still

#8 hitman6003

hitman6003
  • Members
  • PipPipPip
  • Advanced Member
  • 1,807 posts

Posted 24 August 2006 - 11:49 PM

You could also use javascript:

echo '<script type="text/javascript">window.location.href = "somepage.php";</script>';


#9 AdRock

AdRock
  • Members
  • PipPipPip
  • Advanced Member
  • 911 posts

Posted 24 August 2006 - 11:52 PM

Would that work if the user has got javascript disabled in their browser?
If your topic has been solved, please mark the topic as SOLVED.

This helps others from identifying which topics need help still

#10 hitman6003

hitman6003
  • Members
  • PipPipPip
  • Advanced Member
  • 1,807 posts

Posted 24 August 2006 - 11:53 PM

Would any javascript work if the user has javascript disabled?

#11 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 25 August 2006 - 01:20 PM

If javascript is disabled then the answer is no.

#12 Jenk

Jenk
  • Members
  • PipPipPip
  • Advanced Member
  • 778 posts

Posted 25 August 2006 - 01:29 PM

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)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users