URL Redirect with PHP scripts

This sections will contains code regarding different PHP & MySQL features and contains help about php/mysql issues.

URL Redirect with PHP scripts

Postby KingofKings on August 5th, 2008, 8:36 pm

plz tell me how to redirect url with php
:)
KingofKings
 
Posts: 5
Joined: June 1st, 2008, 9:16 am

Re: URL Redirect with PHP scripts

Postby php developer on August 6th, 2008, 3:35 am

In PHP, you can redirect a URL to another by calling a simple function header(). e.g. write the following php code to redirect the user from one page to another.

Code: Select all
  header("Location: you_url_or_page_name");
  exit( );  // write this to stop the execution of the page from this onward


This code will works fine in your PHP script if you havn't output any data to the browser yet. If you are not sure then please write the below line at the top of your php script.

Code: Select all
  ob_start( );


This function don't output any data to the browser until the script is fully executed. If you don't use this function and have output some data event any single character, then you will get the "Headers already sent" like error from the header() function.
php developer
 
Posts: 25
Joined: July 25th, 2008, 4:56 am


Return to PHP / MySQL / XML

Who is online

Users browsing this forum: No registered users and 0 guests