ASP Response.Redirect vs. PHP Header location

Be careful that you don’t have any extra blank spaces in the PHP file… if you try to do a “redirect”, you’ll get an error.

<?php
//****************** INCLUDE *******************
include('include/common.php');
include('include/dbconnect.php');
?> 

<?php
// check if form submitted
if ($_SERVER['REQUEST_METHOD'] == "POST") {....
header( 'Location: /index.php' );     // this will be an error

This instead will be fine.

<?php
//****************** INCLUDE *******************
include('include/common.php');
include('include/dbconnect.php');
?>
<?php
// check if form submitted
if ($_SERVER['REQUEST_METHOD'] == "POST") {

The only difference? …. notice there is no blank line between ?> and <?php

… also, starting a session will also fail?

Warning:  session_start() [function.session-start]: Cannot send session
cache limiter - headers already sent (output started
at /VirtualHosts/TestSite/login.php:6)

Warning:  Cannot modify header information - headers already sent
by (output started at /VirtualHosts/TestSite/login.php:6)
in /VirtualHosts/TestSite/login.php on line 56

All these errors, just because of that blank line… so be careful!

This entry was posted in Uncategorized. Bookmark the permalink.