Jump to content


Cant get cookie or session to work

  • Please log in to reply
1 reply to this topic

Poll: not a pole (0 member(s) have cast votes)

not a pole

  1. duno (0 votes [0.00%])

    Percentage of vote: 0.00%

  2. duno (0 votes [0.00%])

    Percentage of vote: 0.00%

Vote Guests cannot vote

#1 spinanicky

  • New Members
  • Pip
  • Newbie
  • 1 posts

Posted 15 August 2006 - 10:14 AM

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:
Cannot send session cache limiter - headers already sent (output started at E:\Program Files\wamp\www\visgrave\login.php:2) in
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

#2 Ninjakreborn

  • Members
  • PipPipPip
  • Information Technology Specialist
  • 3,922 posts
  • Age:33

Posted 15 August 2006 - 12:37 PM

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.


Business Website: http://www.infotechnologist.biz

Personal Website: http://www.joyelpuryear.com

Blog Site: http://www.realmofwriting.com
Services: Web development, application development, mobile development, and custom development. All services listed on my website.

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users