spinanicky Posted August 15, 2006 Share Posted August 15, 2006 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:[code] <?php //----------------------------USER LOGIN------------------------------------------------- if(!isset($id)){ 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-------------------------------------- else{ $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---------------------------------------// ?>[/code]This should start the session (login.php)[code] <?php session_start(); 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 == "193.171.151.19") $time = '600'; else $time = '1800'; //echo '$time<br>'; //setcookie("id",$username,time()+1800,"/","",0); $_SESSION['userid'] = $row['username']; echo 'Login succesful. Please wait to be redirected<br>'; } else echo 'error'; } ?>[/code]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 helpNicky Quote Link to comment https://forums.phpfreaks.com/topic/17604-cant-get-cookie-or-session-to-work/ Share on other sites More sharing options...
Ninjakreborn Posted August 15, 2006 Share Posted August 15, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/17604-cant-get-cookie-or-session-to-work/#findComment-75067 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.