...

View Full Version : redirect to page using PHP



sgalmeida
01-10-2004, 06:59 PM
Greetings

how can I redirect my page to another using PHP? Using Javascript I can do this using the code window.location='mypage.php'. How can I do this using PHP??

Thank you very much

SÚrgio

dniwebdesign
01-10-2004, 07:08 PM
<?php header("Location: http://www.dniwebdesign.ca.tt"); ?>


This should get what you were looking for.

Nightfire
01-10-2004, 07:15 PM
Just fixing up the code above


<?php
header("Location: http://www.yourdomain.com/nextpage.php");
?>

This must be above any lines of code which output anything to the browser, ie html

dniwebdesign
01-10-2004, 07:17 PM
That's what I put. What happened to my code?

mordred
01-10-2004, 07:22 PM
You forgot to uncheck that checkbox "Automatically parse URLs" beneath the reply textarea.

dniwebdesign
01-10-2004, 10:46 PM
oops

raf
01-10-2004, 11:17 PM
One of my codingprinciples is "Code once, run forever".

If you want to redirect to another page like you asked

Using Javascript I can do this using the code window.location='mypage.php'. How can I do this using PHP??
then you can better use the servervariables to automatically fill in the domain and path to the directory. Like



header('Location: http://'.$_SERVER['HTTP_HOST']
.dirname($_SERVER['PHP_SELF'])
.'/mypage.php');


If it's to a page in your site, but in another server, then you can still use the $_SERVER['HTTP_HOST'] , but after that, you need to enter the path, from the sites root on. Like


header('Location: http://'.$_SERVER['HTTP_HOST']
.'/includes/images/mypage.php');

lslars31
01-11-2004, 01:46 AM
When i was first using php i had trouble with header location because i failed to learn that you cannot output any html, text, or anything like that before you use header("Location: page.php");

bored
01-11-2004, 02:20 AM
If you are redirection immediately on a page then Header works fine. If you want to do a redirect anywhere else on the page I suggest using meta tags.
<meta http-equiv="refresh" content="15; url=http://www.url.com/file.php?antics=sure">
Word.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum