Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > Pro PHP
|
Pro PHP Advanced PHP coding discussions. Beginning-level questions will be redirected to the Beginning PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Pro PHP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 3rd, 2004, 06:01 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 357
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to anshul
Default Redirecting Users

How can I redirect a user to another page using PHP.
I don't wanna use MM variables of Dreamweaver MX.
__________________
`~@#\^%&*/\.<.\/-|+|_!:;..=?>
PHP, SEO | anshul shrivastava | mediasworks.org | FB
 
Old April 3rd, 2004, 04:31 PM
richard.york's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts
Default

In PHP you can redirect a user to another page using the header() function.

<?php
    header('Location: http://www.thesunmagazine.org');
?>

http://www.php.net/header

This function is used to modify the HTTP response headers sent out from the server. For this example the 'Location' header is modified, the browser then picks up on the modification and makes a new request from the new location specified.

Because this function modifies the HTTP headers, it may not be included after output has started from the script.

For example:

<?php
    echo 'Hello, world!';
    header('Location: http://www.thesunmagazine.org');
?>

Would throw a warning level error saying something to the effect that headers cannot be modified, output already started at line x.

This, on the other hand, is valid because it uses output control functions to buffer script output.

<?php

    ob_start();

    echo 'Hello, world!';
    header('Location: http://www.thesunmagazine.org');

    ob_end_flush();

?>

Output from the script is written to the buffer, therefore, when the script reaches header() it is able to make HTTP header changes since nothing has yet been sent to the browser.

Output buffering increases resource consumption slightly because extra memory has to be allocated for the buffer.

More on output buffering:
http://www.php.net/outcontrol

hth,
: )
Rich

::::::::::::::::::::::::::::::::::::::::::
The Spicy Peanut Project
http://www.spicypeanut.net
::::::::::::::::::::::::::::::::::::::::::





Similar Threads
Thread Thread Starter Forum Replies Last Post
redirecting users t0r3ad0r ASP.NET 1.0 and 1.1 Professional 1 October 5th, 2006 10:32 PM
Redirecting logged on Users fletched PHP How-To 1 March 25th, 2004 06:42 PM
Help with redirecting users Sach Classic ASP Databases 1 January 16th, 2004 12:29 PM
Redirecting logged in users zicaden Beginning PHP 3 September 6th, 2003 02:41 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.