Jump to content


This topic is now archived and is closed to further replies.


Cant get cookie or session to work

not a pole  

  1. 1. not a pole

    • duno
    • duno

Recommended Posts

Hey im new here so i dont know if this is in the right thread.. im sure you guys will solve my problem quickly though.

Basically whether i use cookies or session() i get this error:
[b]Cannot send session cache limiter - headers already sent (output started at E:\Program Files\wamp\www\visgrave\login.php:2) in[/b]
its basically just a login script for session tracking. here is the code

This is on the main page:
//----------------------------USER LOGIN-------------------------------------------------
echo '
<form  name="login" action="login.php"  method="post">
<input name="username" size="15" type="text" value=""><br>
      <input name="password" type="password" value="" size="15">
      <input type="submit" value="Log In">
  </form> ';
  //-------------------------LOGED IN DISPLAY DETAILS--------------------------------------
  $connection = mysql_connect("localhost","root","password") or die("could not connect to server");
  mysql_select_db("vis",$connection) or die("could not select DB");
  $sql = "SELECT activation FROM pending where username = '$username'";
  $results = mysql_query($sql);

  while($row = mysql_fetch_array($results)){
  $activation = $row["$activation"];
  echo "<p class=login>Username: $username </p>";
  echo "<p class='status'>your status is:";
  if ($activation = 0) echo 'Awaiting activation code.</p>';
  elseif ($activation = 1) echo 'Active</p>';
  elseif ($activation = 2) echo 'Banned</p>';
  elseif ($activation = 3) echo 'Admin</p>';
  //-------------------------------END OF MEMBER INFO---------------------------------------//


This should start the session (login.php)

header("Cache-control: private");
$connection = mysql_connect("localhost","root","password") or die ("could not connect to the server");
$db = mysql_select_db("vis", $connection) or die ("could not connect to database");
  $sql = "SELECT * FROM pending WHERE username='$username' and password='$password'";
  $results = mysql_query($sql, $connection) or die ("couldnt execture query");
  $num = mysql_numrows($results);
  //echo "$num";
  //INCORRECT AUTHENTICATION--------------------------
  if ($num == 0) echo 'The username or password provided was incorrect, please try again';
  //CORRECT AUTHENTICATION----------------------------- 
  else {
    $row = mysql_fetch_array($results);
  $activation = $row["activation"];
//echo 'test $activation <br>';

if ($activation == 0) {echo '<p> Please check your email and activate your account using your activation code. Remember that
that after you have done this it may take up to another 24 hours untill your account is activated. </p>';}
elseif (($activation == 1)||($activation == 2)||($activation == 3)){

$userip = getenv("REMOTE_ADDR");
if($userip == "") $time = '600';
else $time = '1800';

//echo '$time<br>';

$_SESSION['userid'] = $row['username'];

echo 'Login succesful. Please wait to be redirected<br>';
else echo 'error';


The first code is set up to use the cookie thats why ther is the if(!$id) etc  but that doesnt make a difference to the problem i have. thanks for your help

Share this post

Link to post
Share on other sites
In order for you to use cookies, I have a full tutorial I just created on my site, I hope it helps.  The session part I am still building but most of the cookies, explanation and examplles are there.
www.freelancebusinessman.com under the tutorials section, I tried to set that up, to be totally explanatory to help people learning cookies, the sessions part of that, I am working on lately, It'll be up within half a week.

Share this post

Link to post
Share on other sites


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.