Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

redirect

php

I am trying to redirect a page to another page and that was working successfully. 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

like image 516
max_ Avatar asked Jan 01 '11 16:01

max_


3 Answers

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.

like image 60
jefffan24 Avatar answered Nov 19 '22 20:11

jefffan24


Use refresh meta tag or javascript window.location

like image 29
Dejan Marjanović Avatar answered Nov 19 '22 18:11

Dejan Marjanović


This might help you

setTimeout("javascript window.location",3000)

with regards

Wazzy

like image 1
Wazy Avatar answered Nov 19 '22 19:11

Wazy