Computer ForumsComputers  

Go Back   Computer Forums > Programmers Lounge > Programming Discussions

Reply
 
LinkBack Thread Tools Display Modes
Old 04-13-2007, 06:19 PM   #1 (permalink)
Newb Techie
 
Join Date: Dec 2006
Posts: 5
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   Reply With Quote
Old 04-14-2007, 01:43 PM   #2 (permalink)
True Techie
 
Join Date: May 2006
Location: Chicago IL
Posts: 104
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   Reply With Quote
Old 04-17-2007, 01:03 PM   #3 (permalink)
Ultra Techie
 
synergy's Avatar
 
Join Date: Mar 2005
Location: Somewhere between a 1 and a 0
Posts: 813
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.)
__________________
Frodo failed! BUSH has the ring!
______________________________________
Q9650 E0 stock for now | EVGA nForce 780i SLI
4GB Corsair Dominator DDR2 1066 | (2x) 8800 GT, 700/1000 in SLI
(2x) 74GB Raptors in RAID-0 | (1x) 320 GB Cuda | (1x) 750 GB Cuda
Soundblaster X-FI | Sceptre 20.1" Widescreen LCD Monitor
Gigabyte 3D Aurora Case | Cooler Master Real Power Pro 850W PSU
Thermalright Ultra 120 Extreme HSF
Dual boot, WinXP Pro & Vista Ultimate 64bit | 3dMark06 21,519 | TF2 Stats Page

Last edited by synergy; 04-17-2007 at 01:06 PM.
synergy is offline   Reply With Quote
Old 04-17-2007, 01:34 PM   #4 (permalink)
Master Techie
 
CrazeD's Avatar
 
Join Date: Feb 2006
Location: Maine
Posts: 2,941
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 online now   Reply With Quote
Old 04-30-2007, 04:45 PM   #5 (permalink)
Newb Techie
 
Join Date: Dec 2006
Posts: 5
Send a message via Yahoo to mil1243
Default Re: PHP redirecting

thanks guys!
mil1243 is offline   Reply With Quote
Reply

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


All times are GMT -5. The time now is 10:02 PM.


Powered by vBulletin® Version 3.7.1
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.1.0