开发者

Redirecting a page to another page for 5 seconds then redirecting again

I am trying to redirect a page to another page and that was working suc开发者_开发问答cessfully. However I am trying to redirect the first page to another page with adverts. This page will then redirect to another page after five seconds.

I am trying to do that by doing this:

<?php
include('ads.php');
?>
<?php 
sleep(2);
$url = $_GET['url'];
header("Location: ".$url."");
exit;
?>

However it is showing the advert in ads.php perfectly, but it is not redirecting after five seconds. I am receiving this error in my web browser:

Warning: Cannot modify header information - headers already sent by 
(output started at /home/nucleusi/public_html/adverts/ads.php:1)
in /home/nucleusi/public_html/adverts/index.php on line 7

A typical link I would be redirecting to would be this:

http://domain.com/adverts/index.php/?url=http%3A%2F%2Fitunes.apple.com%2Fmx%2Falbum%2Fstill-got-the-blues%2Fid14135178%3Fi%3D14135158


on the first page(before the ads) before the doctype or html tags put:

<?php header("location: adlocationhere.php"); ?>

Then on the ad page put this:

<?php header("refresh:5;url=secondredirectafter5seconds.php"); ?>

This will redirect your first page immediately and it will redirect your second page after 5 seconds. Hope this helps (its should also get rid of the cannot modify header info if you put it before the doctype and html tags).

EDIT: Also having javascript do it can be a security risk b/c any user can change its location. By doing it this way you have full control over where the user is being directed.


Use refresh meta tag or javascript window.location


This might help you

setTimeout("javascript window.location",3000)

with regards

Wazzy


All pages have headers and content. In order to redirect a visitor to another page, you must do it in the header section of the page. Once you have printed the page content (your ads), you have effectively started the content, in which there is no going back to modify the headers.

The best way to do this is to have a javascript such as

<script>
function redirect() { window.location = '$url'; }
setTimeout("redirect();", 5000);
</script>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜