I need to run a foreach loop and once it's done I'd like to redirect instantly to another page.
How could I do that?
I've tried
header ("location: redirect.php");
But got an error taht the geader is already set...
I need to run a foreach loop and once it's done I'd like to redirect instantly to another page.
How could I do that?
I've tried
header ("location: redirect.php");
But got an error taht the geader is already set...
Headers can only be used at the top of an html file, if my memory serves me correctly. I don't know of any other option in my limited repetoire, except to echo a meta refresh. An html meta refresh looks like this:
<meta http-equiv='refresh' content=10;URL='urlname.html'>
This will refresh the browser in 10 seconds and load the urlname.html page. If you want it immediately, set content=0.
In PHP code, simply surround the meta tag with an echo statement, like this:
echo "<meta .... 'urlname.html'>";
Hope this helps
I'm new on PHP...but on one of my pages I use this
if($variable == null)
{
header("Location: http://www.yourpage/file.php");
}
else
{ }
It works for me...
post your code inside
tags and then we can help you out a bit better...
or, if your foreach loop is actually outputting data to the browser, you could take a look at output buffering. or you could defer output until you are sure you need to. Once any output has been sent to the browser, the header() function will not work, so any white space before the <?php tag at the top of the file will get output to the browser, and you will be unable to do any header stuff (like a redirect or setting a cookie)
If all else fails, this should work:
echo "<script language='javascript'>\n";
echo "window.location.href = 'redirect.php';";
echo "</script>\n";
Originally posted by eerok
If all else fails, this should work:
echo "<script language='javascript'>\n"; echo "window.location.href = 'redirect.php';"; echo "</script>\n";
[/B]
unless of course Jscript is disabled...
Originally posted by tekky
unless of course Jscript is disabled...
That's true. However, there's ways of accounting for that, such as is presented here:
http://grizzlyweb.com/webmaster/javascripts/redirection.asp
If header() can be made to work, then of course that's the way to go. But I've found header() to be very fussy.
OK, what am I doing and why?
I have a page that has multiple listing. Results are usually presented in a list-type format, divided by number off results etc. Each line is a link, when clicked it displays detailed results.
The results also divided by category etc.
Up until now neither I could spider these results with my search engine nor the outside engines could. So what I’ve done, I put a plain vanilla page where I output all results on the same page, do it similarly to the page that has only links to detailed results. So what I end up having is a long page of links to detailed results.
The page is not intended for users and is not linked from anywhere on my site, just sitting by itself. I direct my spider to it, and since it's in a directory, where other spiders come in I assume it'll be picked up as well.
Now, on my side, after I spider the page with links I kill it in my spidered results, so it won't come in my site's search results, however I can not do the same on different engines, and although the probability that this page will ever surface somewhere in search results on Google or Yahoo! is extremely low, I'd like to have that redirect that will forward visitor to the page actually designed for mass consumption.
I like the JavaScript version, which I put after the loop. I assume it gives the page time to output all links and once it's done, make a redirect. It happens pretty fast visually.
The question I have, would the spiders have time t spider all links before they get redirected?
Originally posted by zzz
.....The question I have, would the spiders have time t spider all links before they get redirected?
I'm pretty sure spiders do not respond to javascript as they are programs not browsers.... I may be wrong but...