Re: [PHP] Problem with Redirect



[Didn't I see this thread before?...]

On Thu, February 15, 2007 7:39 pm, Ashish Rizal wrote:
Hi friends, I am having problem with following code.
I have actually made the whole code on same page (login.php) and
the functions that i used in
this code are in functions.php. Now this time it is showing the
warning :
Warning: Cannot modify header information - headers already sent
by (output started at C:\Program
Files\xampp\htdocs\fselection\login.php:1) in C:\Program
Files\xampp\htdocs\fselection\login.php on line 19
The line 19 is header("Location: http://$host$uri/$extra";);

Below is the list of code for login.php.
The Server i am using is SunOS 5.10.

<?php
session_start();
require_once 'functions.php';
$UserName = $_POST['UserName'];
$Password = $_POST['Password'];
$host = $_SERVER['HTTP_HOST'];
$uri = rtrim(dirname($_SERVER['PHP_SELF']), '/\\');
$extra = 'adminlogin.php';
$loc = "\"http://$host$uri/$extra\"";;
if ($_POST){
$error = login_check($_POST);
if (trim ($error)=="")
{
$accesslevel = accessLevel($UserName);
?>
<?php

//At a minimum, you need to do this here:
session_write_close();

if ($accesslevel == "admin"){
$_SESSION["userid"] = login($_POST);
header("Location: http://$host$uri/$extra";);
exit();
}
else if ($accesslevel == "user") {
//echo "this is user";
$_SESSION["userid"] = login($_POST);
header('Location: userlogin.php');
exit();
}
}
else {
print "Error :$error";
}


You could also consider not doing a redirect at all, and just suck in
the appropriate files with 'include' instead of wasting HTTP
connections and bouncing the user like a basketball just to give them
what they want...

PS
exit is not a function and should not have ()

PPS
Blindly cramming all of $_POST into a session variable is a
particularly Bad Idea from a security standpoint, and you need to
study everything on this site before proceeeding:
http://phpsec.org/

--
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some starving artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?
.



Relevant Pages

  • RE: PHP jump to other page
    ... You have an echo or print statement before the redirect (location ... PHP jump to other page ... Warning: Cannot modify header information - headers already sent by ...
    (Ubuntu)
  • Problem with Redirect
    ... Hi friends, I am having problem with following code. ... Warning: Cannot modify header information - headers already sent ...
    (php.general)
  • Re: $HTTP_REFERER crashes my system like clockwork
    ... the error rests with something in there. ... I am very sure nothing is being output before, or after the <?php. ... Warning: Cannot modify header information - headers already sent by ...
    (comp.lang.php)
  • Re: [PHP] Problem Directing the Page with header
    ... Thanks for the quick response. ... Warning: Cannot modify header information - headers already sent ...
    (php.general)
  • Error when doing redirect using
    ... I have index.php in the root directory and I want to redirect the request to ... Cannot modify header information - headers already sent by (output ...
    (alt.php)