Jump to content

[SOLVED] session_start(): Cannot send session cache limiter -


Recommended Posts

 

 

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 :D

 

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>

 

 

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.