Jump to content

header() problem!!


asherinho

Recommended Posts

Hi! I have a login form and I want to direct two different types of users to a their respsective pages.here is the part of the codes

 

if(mysql_num_rows($result) > 0){

$logged_in_user=$uname;

$logged_in_pass=$pass;

session_register("logged_in_user");

session_register("logged_in_pass");

while($record=mysql_fetch_assoc($result)){

if($record["status"]=="administrator"){header( "Location: http://localhost/flis/iframe_admini.php" );exit;}

    elseif($record["status"]=="user"){header( "Location: http://localhost/flis/iframe_user.php" );exit;}

}

 

I get the following warning:

 

Warning: Cannot modify header information - headers already sent by (output started at C:\Program Files\xampp\htdocs\FLIS\login.php:12) in C:\Program Files\xampp\htdocs\FLIS\login.php on line 78

 

Help me,what should I do?

 

Link to comment
https://forums.phpfreaks.com/topic/114626-header-problem/
Share on other sites

Hey projactfear,I read the sticky but there is a problem still,I cant log in at all,it's as if the user name and password variables are not sent to the php page.here are the codes for the userlogin.php

 

 

<? session_start();

ob_start();

if (!isset($_POST['uname']) || !isset($_POST['pass'])) {

header( "Location: http://localhost/flis/index.html" );}

 

 

$uname=trim($uname);

$uname=$_POST['uname'];

$pass=$_POST['pass'];

$passwod=md5($pass);

 

      if($uname && $passwod){

 

if($logged_in_user==$uname && $logged_in_pass==$pass){

echo "<B style='color:red;font-size:15px'>YOU ARE ALREADY LOGGED IN!</B><BR>";

if($record["status"]=="administrator"){header("Location: http://localhost/flis/iframe_adm.php" );exit;}

elseif($record["status"]=="user"){header("Location: http://localhost/flis/iframe_usr.php" );exit;}

}

 

              require("connection.php");

$db=mysql_connect("$host","$user","$password");

mysql_select_db("$dbname",$db);

$result=mysql_query("select * from login where uname='".$uname."' and pass='".$passwod."'");

 

            if(!$result){echo "error in query";}

 

if(mysql_num_rows($result) > 0){

    $logged_in_user=$uname;

    $logged_in_pass=$pass;

    session_register("logged_in_user");

    session_register("logged_in_pass");

      while($record=mysql_fetch_assoc($result)){

        if($record["status"]=="administrator"){header("Location: http://localhost/flis/iframe_adm.php" );exit;}

elseif($record["status"]=="user"){header("Location: http://localhost/flis/iframe_usr.php" );exit;}

                                                                            }

        }

else{header("Location: http://localhost/flis/index2.html");exit;}

}

else{header("Location: http://localhost/flis/idex3.html.php" );exit;}

 

?>

 

What's wrong here                       

Link to comment
https://forums.phpfreaks.com/topic/114626-header-problem/#findComment-589441
Share on other sites

f($logged_in_user==$uname && $logged_in_pass==$pass){
      echo "<B style='color:red;font-size:15px'>YOU ARE ALREADY LOGGED IN!</B><BR>";
      if($record["status"]=="administrator"){header("Location: http://localhost/flis/iframe_adm.php" );exit;}
             elseif($record["status"]=="user"){header("Location: http://localhost/flis/iframe_usr.php" );exit;}
                     }

 

maybe thats causing the error you are trying to output something then redirect

Link to comment
https://forums.phpfreaks.com/topic/114626-header-problem/#findComment-589460
Share on other sites

Man,still is not workin,the same problem

 

<? session_start(); 
ob_start();
if (!isset($_POST['uname']) || !isset($_POST['pass'])) {
header( "Location: http://localhost/flis/index.html" );} 

              
     $uname=trim($uname);
     $uname=$_POST['uname'];
     $pass=$_POST['pass'];
     $passwod=md5($pass);
           
     if($uname && $passwod){
                
  if($logged_in_user==$uname && $logged_in_pass==$pass){
     if($record["status"]=="administrator"){header("Location: http://localhost/flis/iframe_adm.php" );exit;}
            elseif($record["status"]=="user"){header("Location: http://localhost/flis/iframe_usr.php" );exit;}
                    }
                       
             require("connection.php");
  $db=mysql_connect("$host","$user","$password");
  mysql_select_db("$dbname",$db);
  $result=mysql_query("select * from login where uname='".$uname."' and pass='".$passwod."'");
  
            if(!$result){echo "error in query";}
                    
  if(mysql_num_rows($result) > 0){
       $logged_in_user=$uname;
       $logged_in_pass=$pass;
       session_register("logged_in_user");
       session_register("logged_in_pass");
         while($record=mysql_fetch_assoc($result)){
           if($record["status"]=="administrator"){header("Location: http://localhost/flis/iframe_adm.php" );exit;}
     elseif($record["status"]=="user"){header("Location: http://localhost/flis/iframe_usr.php" );exit;}
                                                                            }
           }
     else{header("Location: http://localhost/flis/index2.html");exit;}                      
     }
     else{header("Location: http://localhost/flis/idex3.html.php" );exit;}

ob_end_flush();                   
?>

Link to comment
https://forums.phpfreaks.com/topic/114626-header-problem/#findComment-589469
Share on other sites

I mean your code is very messy. One line if statements are ugly, and hard to read and could cause errors. I sifted through your coding, editing things and making it a bit tidier. Try this:

 

(Your also calling $record when it isn't even set, near the top... Why?)

 

<?php
ob_start();
session_start(); 
if(!isset($_POST['uname']) || !isset($_POST['pass'])){
header( "Location: http://localhost/flis/index.html" );
exit;
} 

  $username = trim($_POST['uname']);
$password = md5($_POST['pass']);
            
   if($username != "" && $password != ""){
                 
   if($_SESSION['logged_in_user'] == $username && $_SESSION['logged_in_pass'] == $password){
      if($record["status"]=="administrator"){
			header("Location: http://localhost/flis/iframe_adm.php" );
			exit;
		}elseif($record["status"]=="user"){
			header("Location: http://localhost/flis/iframe_usr.php" );exit;
		}
    }
                        
	require("connection.php");
	$db=mysql_connect($host,$user,$password);
	mysql_select_db($dbname,$db);

	$result = mysql_query("SELECT * FROM login WHERE uname='".$username."' AND pass='".$password."'");
   
	if(!mysql_result($result,0)){
		die("Error in query.");
	}
                     
  if(mysql_num_rows($result) > 0){
    $_SESSION['logged_in_username'] = $username;
	$_SESSION['logged_in_password'] = $password;

    $record = mysql_fetch_assoc($result);
    
	if($record["status"]=="administrator"){
		header("Location: http://localhost/flis/iframe_adm.php" );
		exit;
	}elseif($record["status"]=="user"){
		header("Location: http://localhost/flis/iframe_usr.php" );
		exit;
	}
  }
}else{
header("Location: http://localhost/flis/index2.html");
exit;
}

ob_end_flush();                   
?>

Link to comment
https://forums.phpfreaks.com/topic/114626-header-problem/#findComment-589480
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.