tags:

views:

137

answers:

5

hai guys, how to redirect to another page in php?plz help me....

A: 
header("location:filename");
die();

it must be called before anything else is output.

Edit: Check out the original question mentioned in the comment, there are way more detailed explanations there.

Pekka
+1  A: 

before any output is done do this:

header('location:myPage.php'); exit; // avoid any unnecessary procedures

Ismael
I think you forgoted an ; after )
Zote
@Zote Thanks. I have edited it. =D
Ismael
+2  A: 

You could have found that easily by googling it

header( "HTTP/1.1 301 Moved Permanently" );
header( "Location: http://www.new-url.com" ); 
exit;
Gordon
+2  A: 

Easy.

<?php
header('Location: /yournewurl/');
?>

If you also need to specify a HTTP status code then you'll need to specify that too. But given the simplistic nature of your question I'll presume you don't know what a HTTP status code is. Therefore, if this a permanent redirect, i.e. you want to remove this page but send everyone to a new page in its place, then you want to use a HTTP status code of 301.

If the redirect is only for a set amount of time (e.g. whilst you're performing site updates) then you'll want to send a status code of 302.

See Gordon's answer above for the syntax of those types of redirects.

Martin Bean
A: 

It is really cheezy (and really has nothing to do with PHP, but when I forward to a page in a PHP file, I do it with Javascript like so:

?>
<script language="Javascript">
     location.href='URL_TO_FORWARD_TO';
</script>
<?php

The PHP tags allow existing PHP code to exist around this block.

Just a thought. PEACE!!!!!!!

Carlson Technology
This method fails when JavaScript is disabled though.
Jon Winstanley