Forward command

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Tony Brush
Forum Newbie
Posts: 2
Joined: Fri Apr 19, 2002 6:18 am

Forward command

Post by Tony Brush »

Hi all,
I'm a PHP newbie.
Have studied manual & searched tutorials without luck...
I need to send the user to a specified URL at a point in code - hyperlinks are not appropriate as it is not to be reliant on user interaction. Is there a command something like Forward("next.htm") ?
Thanks for help,
Tony
User avatar
Phirus
Forum Commoner
Posts: 37
Joined: Thu Apr 18, 2002 4:10 pm
Contact:

Post by Phirus »

Use either one of these:

Code: Select all

<?
  header("Location: http://www.example.com/"); 
?>
OR

Code: Select all

<meta http-equiv="refresh" content="0;URL=http://www.example.com">
Hope that helps,

PhIrUs
User avatar
hex
Forum Commoner
Posts: 92
Joined: Sat Apr 20, 2002 3:20 am
Location: UK

Post by hex »

The header() function will only work at the start of a page (before any content is outputted). You'd have to use JavaScript or something to do it mid-page probably.
I had this script from ages ago:

Code: Select all

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd">
<html>
<head>
<script language="JavaScript1.1">
<!--
location.replace("http://www.new.site/page.html");
//-->
</script>
<noscript>
<meta http-equiv="Refresh" content="0; url="http"://www.new.site/page.html" />
</noscript>
</head>
<body>
This page has moved to a <a href="http://www.new.site/page.html">new location</a>.
</body>
</html>
romeo
Forum Contributor
Posts: 138
Joined: Sun Apr 21, 2002 12:50 pm

try and use header...

Post by romeo »

both javascript and meta refresh can be disabled and sometimes are because redirects can be a security risk when playing with personal info.
8O
jason
Site Admin
Posts: 1767
Joined: Thu Apr 18, 2002 3:14 pm
Location: Montreal, CA
Contact:

Post by jason »

If you are having problems with using header() because of the "headers already sent error", look up output buffering in the manual as well as here: http://www.newbienetwork.net/content.php?id=42
Post Reply