asherinho Posted July 14, 2008 Share Posted July 14, 2008 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? Quote Link to comment Share on other sites More sharing options...
JasonLewis Posted July 14, 2008 Share Posted July 14, 2008 There is a sticky thread in the PHP Help board. http://www.phpfreaks.com/forums/index.php/topic,37442.0.html Quote Link to comment Share on other sites More sharing options...
mmarif4u Posted July 14, 2008 Share Posted July 14, 2008 Put this at very top of the page after php tag. ob_start(); Quote Link to comment Share on other sites More sharing options...
JasonLewis Posted July 14, 2008 Share Posted July 14, 2008 Put this at very top of the page after php tag. ob_start(); I wouldn't personally suggest this, as it isn't really "solving" the error. Quote Link to comment Share on other sites More sharing options...
asherinho Posted July 14, 2008 Author Share Posted July 14, 2008 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 Quote Link to comment Share on other sites More sharing options...
JasonLewis Posted July 14, 2008 Share Posted July 14, 2008 I didn't read your code. Please wrap code in [ code ] tags or [ php ] tags. Remember to place an ob_end_flush() at the end of the document if your insisting on using output buffering. Quote Link to comment Share on other sites More sharing options...
Juan Dela Cruz Posted July 14, 2008 Share Posted July 14, 2008 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 Quote Link to comment Share on other sites More sharing options...
asherinho Posted July 14, 2008 Author Share Posted July 14, 2008 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(); ?> Quote Link to comment Share on other sites More sharing options...
Juan Dela Cruz Posted July 14, 2008 Share Posted July 14, 2008 are you sure you are not including this file somewhere ? Quote Link to comment Share on other sites More sharing options...
JasonLewis Posted July 14, 2008 Share Posted July 14, 2008 That has got to be some darn messy code. Sorry. Quote Link to comment Share on other sites More sharing options...
Juan Dela Cruz Posted July 14, 2008 Share Posted July 14, 2008 not sure but that maybe the reason of having this error? if you do this html here and stuff to be displayed php here i guess that will cause error Quote Link to comment Share on other sites More sharing options...
asherinho Posted July 14, 2008 Author Share Posted July 14, 2008 I didnt include it anywhere. What do u mean Projectfear? I didnt exactly get u Juan Quote Link to comment Share on other sites More sharing options...
JasonLewis Posted July 14, 2008 Share Posted July 14, 2008 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(); ?> Quote Link to comment Share on other sites More sharing options...
asherinho Posted July 14, 2008 Author Share Posted July 14, 2008 I tried the codes but it's not working.Nothing is been done,nothing is displayed but on the url on top of the browser it shows the url to the userlogin.php page Quote Link to comment Share on other sites More sharing options...
samshel Posted July 14, 2008 Share Posted July 14, 2008 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. Quote Link to comment Share on other sites More sharing options...
asherinho Posted July 14, 2008 Author Share Posted July 14, 2008 can you pass through the code above posted by projectfear? and try to cross check to find any error Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.