devvie Posted July 27, 2006 Share Posted July 27, 2006 Im getting this message when i load my login page. its brand new, so i hjave a million directions i can go. I want a secure login with sessions so that i can remove the logins on other outside apps on the site. [code]Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /home/c4sale/public_html/main/Connections/connection.php:12) in /home/c4sale/public_html/main/login.php on line 36Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/c4sale/public_html/main/Connections/connection.php:12) in /home/c4sale/public_html/main/login.php on line 36[/code]heres the header of my page[code]<?php require_once('Connections/connection.php'); ?><?phpif (!function_exists("GetSQLValueString")) {function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue;}}?><?php// *** Validate request to login to this site.if (!isset($_SESSION)) { session_start();}$loginFormAction = $_SERVER['PHP_SELF'];if (isset($_GET['accesscheck'])) { $_SESSION['PrevUrl'] = $_GET['accesscheck'];}if (isset($_POST['textfield'])) { $loginUsername=$_POST['textfield']; $password=$_POST['textfield2']; $MM_fldUserAuthorization = ""; $MM_redirectLoginSuccess = "user/index.php"; $MM_redirectLoginFailed = "login_deny.php"; $MM_redirecttoReferrer = true; mysql_select_db($database_forsale, $forsale); $LoginRS__query=sprintf("SELECT Desired_Username, Password FROM login1_table WHERE Desired_Username=%s AND Password=%s", GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text")); $LoginRS = mysql_query($LoginRS__query, $forsale) or die(mysql_error()); $loginFoundUser = mysql_num_rows($LoginRS); if ($loginFoundUser) { $loginStrGroup = ""; //declare two session variables and assign them $_SESSION['MM_Username'] = $loginUsername; $_SESSION['MM_UserGroup'] = $loginStrGroup; if (isset($_SESSION['PrevUrl']) && true) { $MM_redirectLoginSuccess = $_SESSION['PrevUrl']; } header("Location: " . $MM_redirectLoginSuccess ); } else { header("Location: ". $MM_redirectLoginFailed ); }}?>[/code]and heres the form[code]<form name="form1" method="POST" action="<?php echo $loginFormAction; ?>"> <label>Username<br><input name="textfield" type="text" accesskey="l" tabindex="1" size="15"><br></label><label>Password<br><input name="textfield2" type="password" tabindex="2" size="15"><br></label><input type="submit" name="Submit" value="Submit" tabindex="3"></form>[/code] Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted July 27, 2006 Share Posted July 27, 2006 What's line 12 of Connections/connection.php? The error message is complaining that this line already sent output to the browser.Ken Quote Link to comment Share on other sites More sharing options...
devvie Posted July 27, 2006 Author Share Posted July 27, 2006 thats where the bugger comes in, there is no line 12, heres teh complete lines, thats it. 10 lines<?php# FileName="Connection_php_mysql.htm"# Type="MYSQL"# HTTP="true"$hostname_forsale = "localhost";$database_forsale = "db";$username_forsale = "user";$password_forsale = "pass";?> Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted July 27, 2006 Share Posted July 27, 2006 Then you must have blank lines before the "<?php" or after the "?>".Ken Quote Link to comment Share on other sites More sharing options...
devvie Posted July 27, 2006 Author Share Posted July 27, 2006 you know i read soemthing about a cache limiter recently, and i never activated it(if necessary), or payed any attention it, and i notice that in the error message. could this be it?BUT, it also says session headers already started, so might i need to do a session destroy or unset first? Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted July 27, 2006 Share Posted July 27, 2006 Did you read the sticky note at the top of this forum entitled "HEADER ERRORS - READ HERE BEFORE POSTING THEM"?Ken Quote Link to comment Share on other sites More sharing options...
redarrow Posted July 28, 2006 Share Posted July 28, 2006 if (isset($_SESSION['PrevUrl']) && true) { $MM_redirectLoginSuccess = $_SESSION['PrevUrl']; header("Location: " . $MM_redirectLoginSuccess ); }} else { header("Location: ". $MM_redirectLoginFailed ); }} Quote Link to comment Share on other sites More sharing options...
devvie Posted July 28, 2006 Author Share Posted July 28, 2006 Ken, i wouldnt have understood it completely anyway, but now looking back on it, thanks for the link, becuase it starting to make more sense. I really dont understand what headers are yet. I read chapters of php everyday, so its coming more clear, but headers are still mystery for the most part.redarrow, whats teh code you sent me, it looks like its a direct copy from my page. can you give a comment with your post?if (isset($_SESSION['PrevUrl']) && true) { $MM_redirectLoginSuccess = $_SESSION['PrevUrl']; } header("Location: " . $MM_redirectLoginSuccess ); } else { header("Location: ". $MM_redirectLoginFailed ); }} Quote Link to comment Share on other sites More sharing options...
akrytus Posted July 28, 2006 Share Posted July 28, 2006 You did this code in dreamweaver? I had the same problem and the code looks identical to the code that dreamweaver produces. I played around with it for several hours before I got around it. Wish I was sweet enough to tell you what I did to fix it. Chances are though, if I were to do it again, I would run into the same problem! Let me know how it works out so I know in the future. Good luck! Quote Link to comment Share on other sites More sharing options...
Ninjakreborn Posted July 28, 2006 Share Posted July 28, 2006 THe bottom line is if you havesession_start();at the first line of code, ther eshould be no reason why it's saying headers already sent. Quote Link to comment Share on other sites More sharing options...
devvie Posted July 28, 2006 Author Share Posted July 28, 2006 Akr, i use dreamweaver but i got this code from hotscripts i believeabout that businessman, you notice its NOT the first line of code, its like the 30th..... look at my php code ont he top of this post. would you consider the session start to be the first line of code in that example? if so, then i am really confused. Or, is that the problem, where the session start shoudl be on LINE1??? Quote Link to comment Share on other sites More sharing options...
Ninjakreborn Posted July 28, 2006 Share Posted July 28, 2006 No matter what if session_start();is not LINE 1, ONLY, no other line, no spaces, no text, nothing at all before session_start()then error headers already sent, always pop's up at the top of the screenalways cop y and paste session_start() above all pages using sessions.Preferably in it's own<?phpsession_start();?> exactly like that before html or anythingif you have any includes, it's best to do them in another island, below the session start code island 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.