How to redirect page using PHP with values?

Monday, January 2nd, 2012

Here is the code for simple PHP page redirect. The search engine friendly way of redirecting is the 301 redirect.

1
2
3
4
<?php
	Header("HTTP/1.1 301 Moved Permanently"); 
	header( 'Location: http://www.yoursite.com/page.html' ) ;
?>

Note that if you do not include the first Header line above, the redirect still works. But, instead of a 301 redirect, now it becomes a 302 (temporary) redirect.

Now if you want to redirect to perticluer user page then you need to include user id in the url. Here is the code:

1
2
3
<?php
	header("Location: userpage.php?id=".$userId);
?>
Avatar of Peter Vegas

Author Name :
Peter Vegas

Total : 0 Comment


Leave a Reply

Question and Answer
C/C++ Unix & Linux Wordpress
Source codes
C C++ Java

Free email signup

Email: