Computer Forums

Member Login

Remember Me? Sign Up! | Forgot Password
 
Slogan
 
Closed Thread
Old 04-13-2007, 06:19 PM   #1 (permalink)
 
Newb Techie

Join Date: Dec 2006

Posts: 5

mil1243

Send a message via Yahoo to mil1243
Default PHP redirecting

Is there any code in PHP that shows a page for a specific time i.e 10 seconds
and automaticlly redirect the page to the other URL ?!
mil1243 is offline  
Old 04-14-2007, 01:43 PM   #2 (permalink)
 
True Techie

Join Date: May 2006

Location: Chicago IL

Posts: 104

thejeremy

Send a message via AIM to thejeremy
Default Re: PHP redirecting

You don't need PHP to do it. This is a valid HTML tag I've used before:

<META HTTP-EQUIV="Refresh" CONTENT="10; URL=main.html">

This should be put in the <HEAD> tag of the page you want showing for 10 seconds or so. The "10" means the page will be redirected to the page in the URL field after 10 seconds ("main.html" here).

If you still want to use PHP, you can redirect the user to another site using

header("Location: somelink.php");

...but only if there are no HTML tags prior to this line in your code. To do it after a certain amount of time, it looks similar to the code inside the first tag up there:

header('Refresh: 10; URL=http://www.example.com');

Hope this helps.
__________________
CPU: AMD Athlon 64 X2 5200+ Windsor, 2.6 GHz
RAM: CORSAIR XMS2 2GB 240-Pin DDR2
VIDCARD: EVGA PCI-Express x16 GeForce 7900GS 256MB
MOBO: ASUS M2N-SLI Deluxe AM2
HDD: Seagate Barracuda 320GB 7200 RPM SATA

my blog: http://jspot.gotdns.com
thejeremy is offline  
Old 04-17-2007, 01:03 PM   #3 (permalink)
synergy's Avatar
 
Monster Techie

Join Date: Mar 2005

Location: Somewhere between a 1 and a 0

Posts: 1,677

synergy will become famous soon enoughsynergy will become famous soon enough

Send a message via MSN to synergy Send a message via Yahoo to synergy Send a message via Skype™ to synergy
Default Re: PHP redirecting

You can use php for other stuff and insert javascript into the page for the redirect.

For instance this is a page I did that redirects after showing the results of a contact form:

PHP Code:
<?php
bunch of php code here
<script Language="JavaScript">
  <!--

       var 
URL   "http://www.mysite.com"
       
       
var speed 3000

       
function reload(){

       
location URL

       
}

       
setTimeout("reload()",speed);

  
//-->
</script>

<p><strong>Redirecting in 3 seconds <br />
Click <a href="http://www.mysite.com">here</a> if you would not like to wait </strong></p>
<p> </p>

<?php 
}
?>
var URL is the link you want to redirect to
var speed is how long it will take (ms, 3000=3 secs, 5000=5 secs, etc.)
__________________

Windows 7 Professional 64-bit
HTPC: Phenom II X4 920 | Biostar TA790GX XE mATX w/ ATI HD 3300 IGP | 4 GB Dominators DDR2 1066
LG Blu-Ray/HD-DVD ROM + DVD RW | WD Caviar 1 TB | 250 GB Cuda | Antec Veris Fusion Black HTPC Case
Logitech diNovo Edge KB | Win7 Pro 64-bit

3dMark06 23,159 | 3dMark Vantage 23,579 | TF2 Stats Page

Last edited by synergy; 04-17-2007 at 01:06 PM.
synergy is offline  
Old 04-17-2007, 01:34 PM   #4 (permalink)
CrazeD's Avatar
 
Wizard Techie

Join Date: Feb 2006

Location: Maine

Posts: 3,683

CrazeD will become famous soon enough

Send a message via AIM to CrazeD Send a message via MSN to CrazeD
Default Re: PHP redirecting

If you use
Code:
<?php

header('Location: blahblah.com');

?>
in mid-HTML, you'll get a "Headers already sent" error.

To fix that, you'll have to use output buffering.

Example:
Code:
<?php
ob_start();
header('Location: blahblah.com');
ob_end_flush();
?>
This will buffer the PHP and execute any PHP scripts between the ob_start() and ob_end_flush() functions before it does anything else.

It's best to put ob_start(); as the very first piece of code on your page, and put ob_end_flush(); at the very end, therefore buffering (executing) the PHP before anything else.
__________________

Need website help? PM me!
CrazeD is offline  
Old 04-30-2007, 04:45 PM   #5 (permalink)
 
Newb Techie

Join Date: Dec 2006

Posts: 5

mil1243

Send a message via Yahoo to mil1243
Default Re: PHP redirecting

thanks guys!
mil1243 is offline  
 
Closed Thread

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
php help ben_ben Programming Discussions 8 04-20-2007 05:32 PM
PHP 2-player game? thejeremy Programming Discussions 4 04-09-2007 06:01 PM
Remote file access w/ IP + PHP? thejeremy Programming Discussions 2 04-04-2007 05:24 PM
is this version of PHP installer outdated? kwokwai Programming Discussions 2 04-04-2007 03:05 AM