dbillings Posted August 15, 2006 Share Posted August 15, 2006 I read the header error bit that is posted and it didn't help me. I keep receiving the following error message and can't figure out why. The login script works fine on it's own but when I include it in my index.php page it gives me the error.Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at /home/www/Devendea/lux/index.php:5) in /home/www/Devendea/lux/login.php on line 2I made sure that there wasn't any white space before or after my <?php, ?> tags and I still get the error. Here's the script.[code]<?phpsession_start();include ("mysql_connect1.php");if (isset($_REQUEST['submit'])){ $u = $_REQUEST['loginname']; $p = $_REQUEST['pass2']; $hp = md5($p); $query = "SELECT loginname, admin, member, wararranger FROM users WHERE loginname ='$u' AND pass2 = '$hp'"; $result = @mysql_query($query)or die ('Query could not be processed: '.mysql_error()); $row = mysql_fetch_array ($result, MYSQL_NUM); if($row){ $_SESSION['loginname'] = $row[0]; $_SESSION['admin'] = $row[1]; $_SESSION['member'] = $row[2]; $_SESSION['wararranger'] = $row[3]; echo "<p>Welcome,<b> {$_SESSION['loginname']}</b>!</p>"; }elseif(!isset($_SESSION['loginname'])){ echo "<p>Invalid login attempt!</p>"; }}if (isset($_SESSION['loginname'])){ }else{ include ("loginform.php");}?>[/code]And here is the index.php I'm using and receiving the error on. I tried to keep it simple to see what the problem is but the problem remains.[code]<html><head></head><body><?php include ("login.php");?></body></html>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/17587-solved-session_start-trouble/ Share on other sites More sharing options...
Chetan Posted August 15, 2006 Share Posted August 15, 2006 If your index.php is this it would be better[code]<?php include ("login.php");?><html><head></head><body></body></html>[/code]Since sessions need nothing to be before them even HTML Quote Link to comment https://forums.phpfreaks.com/topic/17587-solved-session_start-trouble/#findComment-74930 Share on other sites More sharing options...
dbillings Posted August 15, 2006 Author Share Posted August 15, 2006 Worth a try. Quote Link to comment https://forums.phpfreaks.com/topic/17587-solved-session_start-trouble/#findComment-75121 Share on other sites More sharing options...
king arthur Posted August 15, 2006 Share Posted August 15, 2006 Well yes, that would be the problem. You have already started rendering the page by the time the PHP script is included, hence the "headers already sent" error. Quote Link to comment https://forums.phpfreaks.com/topic/17587-solved-session_start-trouble/#findComment-75124 Share on other sites More sharing options...
redarrow Posted August 15, 2006 Share Posted August 15, 2006 make sure that theres no white spaces and always put the session_start() at the top good luck. Quote Link to comment https://forums.phpfreaks.com/topic/17587-solved-session_start-trouble/#findComment-75125 Share on other sites More sharing options...
Daniel0 Posted August 15, 2006 Share Posted August 15, 2006 You could move the session_start() function to the top of the other file.When you include your file like that it will become: [code]<html><head></head><body><?phpsession_start();include ("mysql_connect1.php");if (isset($_REQUEST['submit'])){ $u = $_REQUEST['loginname']; $p = $_REQUEST['pass2']; $hp = md5($p); $query = "SELECT loginname, admin, member, wararranger FROM users WHERE loginname ='$u' AND pass2 = '$hp'"; $result = @mysql_query($query)or die ('Query could not be processed: '.mysql_error()); $row = mysql_fetch_array ($result, MYSQL_NUM); if($row){ $_SESSION['loginname'] = $row[0]; $_SESSION['admin'] = $row[1]; $_SESSION['member'] = $row[2]; $_SESSION['wararranger'] = $row[3]; echo "<p>Welcome,<b> {$_SESSION['loginname']}</b>!</p>"; }elseif(!isset($_SESSION['loginname'])){ echo "<p>Invalid login attempt!</p>"; }}if (isset($_SESSION['loginname'])){ }else{ include ("loginform.php");}?></body></html>[/code]And as you see, then session_start() is not run before something is sent to output. Quote Link to comment https://forums.phpfreaks.com/topic/17587-solved-session_start-trouble/#findComment-75143 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.