iamali Posted April 2, 2006 Share Posted April 2, 2006 Hi,I have a problem with a login code I've written:[code]<?phpsession_start();$user = $_POST['username'];$pass = $_POST['password'];$_SESSION['username'] = $user;$_SESSION['password'] = $pass;?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /><title>PHP Photograph Gallery</title><link href="style.css" rel="stylesheet" type="text/css" /></head><body><?php include("links_private.inc");?><table class="page" align="center" cellpadding="15" cellspacing="0"><tr><td class="header"><h1>PHP Photograph Gallery</h1><br />Login Successful</td></tr><tr><td><?phpif ((!$_POST['username']) || (!$_POST['password'])) { header("Location:login.htm"); exit;}include("dbconnect.inc");$sql = "SELECT f_name, l_name from tbl_users where username = '$_POST[username]' AND password = password('$_POST[password]')" or die(mysql_error());$result = mysql_query($sql, $conn) or die(mysql_error());$num = mysql_num_rows($result); if ($num == 1) { $f_name = mysql_result($result,0,'f_name'); $l_name = mysql_result($result,0,'l_name');} else { header("Location:login.htm"); exit;}echo "<p class=\"centre\">Welcome $f_name $l_name!</p>"; ?> <p class="centre"><a href="admin.php">Continue to Gallery Administration</a></p></td></tr></table></body></html>[/code]whenever I try to log in with the username and password field as empty it gives me this error:[code]Warning: Cannot modify header information - headers already sent by (output started at C:\Inetpub\wwwroot\galleryuploader\auth_login.php:18) in C:\Inetpub\wwwroot\galleryuploader\auth_login.php on line 28[/code]and when I try and log in with incorrect details in the username and password field it gives me this error:[code]Warning: Cannot modify header information - headers already sent by (output started at C:\Inetpub\wwwroot\galleryuploader\auth_login.php:18) in C:\Inetpub\wwwroot\galleryuploader\auth_login.php on line 45[/code]...when i was hoping it would use the 'header("Location:login.htm");' to send the user back to the login page. Any ideas why it's doing this anyone?Thanks! Quote Link to comment Share on other sites More sharing options...
redbullmarky Posted April 2, 2006 Share Posted April 2, 2006 hithere are several pinned topics entitled things such as 'Read here before posting' and 'Do you have header/session problems'. You really should read those first.CheersMark Quote Link to comment Share on other sites More sharing options...
emehrkay Posted April 2, 2006 Share Posted April 2, 2006 you have some stuff bering printed to the brower window befroe you call header. you need to put header before any output, i dont see why you can not do that in your code. just try to move it above the html Quote Link to comment Share on other sites More sharing options...
Desdinova Posted April 2, 2006 Share Posted April 2, 2006 or put a ob_start(); right at the beginning of the page, and a ob_end_flush(); at the very end. else, what emerhka (or something, can't remember sorry ;) ) said. Quote Link to comment Share on other sites More sharing options...
iamali Posted April 2, 2006 Author Share Posted April 2, 2006 [!--quoteo(post=360866:date=Apr 2 2006, 03:11 PM:name=redbullmarky)--][div class=\'quotetop\']QUOTE(redbullmarky @ Apr 2 2006, 03:11 PM) [snapback]360866[/snapback][/div][div class=\'quotemain\'][!--quotec--]hithere are several pinned topics entitled things such as 'Read here before posting' and 'Do you have header/session problems'. You really should read those first.CheersMark[/quote]Sorry I couldn't find them, there was only:Pinned: Have you been helped here? Pinned: Simple Error Handling/Form Validation Logic Pinned: MYSQL_SOMETHING - INVALID RESOURCEPinned: DO YOU HAVE PHP SESSION PROBLEMS? at the top of the forum. :-S[!--quoteo(post=360867:date=Apr 2 2006, 03:12 PM:name=emehrkay)--][div class=\'quotetop\']QUOTE(emehrkay @ Apr 2 2006, 03:12 PM) [snapback]360867[/snapback][/div][div class=\'quotemain\'][!--quotec--]you have some stuff bering printed to the brower window befroe you call header. you need to put header before any output, i dont see why you can not do that in your code. just try to move it above the html[/quote]oh i see, so you can't have any HTML or anything before headers? ok I've moved it around and it works now :-) thanks! Quote Link to comment Share on other sites More sharing options...
kwstephenchan Posted April 2, 2006 Share Posted April 2, 2006 Desdinova is right. Put ob_start() at the very first line of the page and ob_end_flush() at the end. That should solve your problem. Quote Link to comment Share on other sites More sharing options...
redbullmarky Posted April 2, 2006 Share Posted April 2, 2006 [!--quoteo(post=360884:date=Apr 2 2006, 03:47 PM:name=newPHPer)--][div class=\'quotetop\']QUOTE(newPHPer @ Apr 2 2006, 03:47 PM) [snapback]360884[/snapback][/div][div class=\'quotemain\'][!--quotec--]Desdinova is right. Put ob_start() at the very first line of the page and ob_end_flush() at the end. That should solve your problem.[/quote]whilst ob_start, etc will work, i kinda sometimes feel that it should be used as a last resort if you HAVE to resend the headers. otherwise, it's just a form of masking a problem or something that shouldn't be there.[a href=\"http://www.phpfreaks.com/forums/index.php?showforum=12\" target=\"_blank\"]http://www.phpfreaks.com/forums/index.php?showforum=12[/a] 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.