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
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
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
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
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
Share on other sites

Generally header errors are caused when you print something before redirecting. Check if you have printed/echoed something purposely or by mistake.

 

Even a space or a newline at the end of included file after ?> tag can cause problems.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.