Tylor_Famous Posted January 29, 2008 Share Posted January 29, 2008 Hello, I am working on a login form and am having trouble. I am getting the following error: Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at /home/lin/index.php:13) in /link/myfile.php on line 3 I don't quite get this because on line three is nothing more than session_start(); I saw some one say that the error was from spaces before the <?php tag but I have NO spaces… Also, thought I would just let you know, this code is going to be the menu bar for a site of mine so I don't have opening (or closing) <html> tags because I am going to include it into the site with php. And , as you can probably see by my coding, I am new to php and mysql so a simple explanation with small words is appreciated Here is the entire code (a little bit still in the works). I hope you can help me find my answer. Thanks! <?php session_start(); include("db.php"); loginInfo(); $table = 'login'; $whattodo = "notloggedin"; if($_SESSION['session_var'] == "skiplogin"){ $textbox = "You are now logged in!<br> Would you like to <form action=\" $PHP_SELF \" method=\"post\" name=\"logout\"> <input type=\"hidden\" name=\"$whattodo\" value=\"logout\" /> <input name=\"logout\" type=\"submit\" value=\"Logout\" /> </form> "; ///////////////// Relogin \\\\\\\\\\\\\\\\\\\\\\\ } else if ( $whattodo == "relogin" ){ mysql_pconnect($host, $user, $pass); mysql_select_db($database); $reloginname = $_POST["username"]; $reloginpass = $_POST["password"]; $query = "SELECT password FROM $table WHERE username = '$reloginname' "; $result = mysql_query($query); $row = mysql_fetch_array($result); if($reloginpass == $row['password']){ $textbox = "You are now logged in!"; $_SESSION['session_var'] = "skipLogin"; } else { $textbox="sorry something is wrong"; session_destroy(); } } else if ($whattodo == "notloggedin"){ $textbox = " <form action=\" $PHP_SELF \" method=\"post\" name=\"loginform\"> <ul> <li>Username:</li> <li><input name=\"username\" type=\"text\" maxlength=\"20\"></li> <li>Passoword:</li> <li><input name=\"password\" type=\"password\" maxlength=\"20\"></li> <li><input name=\"Login\" type=\"submit\" value=\"Login\"></li> <li>Don't have an account? <a href=\"#\">sign up</a>!</li> <input type=\"hidden\" name=\"$whattodo\" value=\"relogin\"> </ul> </form>"; } else if ($whattodo =="logout"){ session_destroy(); $whattodo = "notloggedin"; } ?> <div id="menubox1"> <h3>Account Information:</h3> <?php echo "$textbox" ?> </div> <div id="menubox2"> <h3>Navigation:</h3> <ul> <li><a href="#">Home Page</a></li> <li><a href="#">Link will go here</a></li> <li><a href="#">Link will go here</a></li> <li><a href="#">Link will go here</a></li> <li><a href="#">Link will go here</a></li> </ul> </div> <div id="menubox3"> <h3>Navigation:</h3> <ul> <li><a href="#">Link will go here</a></li> <li><a href="#">Link will go here</a></li> <li><a href="#">Link will go here</a></li> <li><a href="#">Link will go here</a></li> <li><a href="#">Link will go here</a></li> </ul> </div> <div id="menubox4"> <h3>Navigation:</h3> <ul> <li><a href="#">Link will go here</a></li> <li><a href="#">Link will go here</a></li> <li><a href="#">Link will go here</a></li> <li><a href="#">Link will go here</a></li> <li><a href="#">Link will go here</a></li> </ul> </div> Quote Link to comment https://forums.phpfreaks.com/topic/88415-solved-session_start-cannot-send-session-cache-limiter/ Share on other sites More sharing options...
wildteen88 Posted January 29, 2008 Share Posted January 29, 2008 I presume the above code gets included in index.php file? If so the reason you are getting the error is because index.php is outputting some form of data (be it text/html/whitespace) on/around line 13. I would recommend you to remove session_start() function from the above code and place it at the top of parent file (index.php) instead. You do need to add session_start() to files which get included. Included files don't get parsed separately. Quote Link to comment https://forums.phpfreaks.com/topic/88415-solved-session_start-cannot-send-session-cache-limiter/#findComment-452580 Share on other sites More sharing options...
Tylor_Famous Posted January 29, 2008 Author Share Posted January 29, 2008 Thanks so much! Quote Link to comment https://forums.phpfreaks.com/topic/88415-solved-session_start-cannot-send-session-cache-limiter/#findComment-452809 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.