xux Posted August 29, 2006 Share Posted August 29, 2006 Hi everybody, I am trying to implement session control woth a login mechanism.it has being generating an error which i have found difficult to rectify.It has been generating[code]Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at D:\wwwroot\t\login.php:12) in D:\wwwroot\t\login.php on line 236[/code]please i need help.Thanks Quote Link to comment https://forums.phpfreaks.com/topic/19022-had-a-problem-with-sessionplease-help/ Share on other sites More sharing options...
Ifa Posted August 29, 2006 Share Posted August 29, 2006 Try adding the session_start(): to the top of the file, or if you are including the file, at the top of the file that is including it.... Quote Link to comment https://forums.phpfreaks.com/topic/19022-had-a-problem-with-sessionplease-help/#findComment-82253 Share on other sites More sharing options...
Orio Posted August 29, 2006 Share Posted August 29, 2006 You cant call session_start(), header(), setcookie() and other fucntions after the script outputs something. session_start() should come in the begining.Can you post your code so I could show you where you are wrong?Orio. Quote Link to comment https://forums.phpfreaks.com/topic/19022-had-a-problem-with-sessionplease-help/#findComment-82254 Share on other sites More sharing options...
xux Posted August 29, 2006 Author Share Posted August 29, 2006 Thanks,here is my code[code]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /><title>Login</title></head><body><?php session_start(); if (isset($HTTP_POST_VARS['user_name'])&&(isset($HTTP_POST_VARS['pwd']))) { // getting data from the login form $user_name = $HTTP_POST_VARS['user_name']; $pwd = $HTTP_POST_VARS['pwd'];$connection = mysql_pconnect('localhost', 'root', 'justus') or die ('Unable to connect!');// select database for usemysql_select_db('sme_cms') or die ('Unable to select database!');$query = 'select * from auth ' ."where name='$user_name' " ." and pass=password('$pwd')"; $result = mysql_query($query); if (mysql_num_rows($result) >0 ) { // if they are in the database register the user id $HTTP_SESSION_VARS['valid_user'] = $user_name; }}if (isset($HTTP_SESSION_VARS['valid_user'])) { echo 'You are logged in as: '.$HTTP_SESSION_VARS['valid_user'].' <br />'; echo '<a href="logout.php">Log out</a><br />'; } else { if (isset($user_name)) { // if they've tried and failed to log in echo 'Could not log you in'; } else { // they have not tried to log in yet or have logged out echo 'You are not logged in.<br />'; } } ?> </body></html>Thanks [/code] Quote Link to comment https://forums.phpfreaks.com/topic/19022-had-a-problem-with-sessionplease-help/#findComment-82261 Share on other sites More sharing options...
Ifa Posted August 29, 2006 Share Posted August 29, 2006 [code]<?PHP session_start(); ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /><title>Login</title></head><body><?php if (isset($HTTP_POST_VARS['user_name'])&&(isset($HTTP_POST_VARS['pwd']))) { // getting data from the login form $user_name = $HTTP_POST_VARS['user_name']; $pwd = $HTTP_POST_VARS['pwd'];$connection = mysql_pconnect('localhost', 'root', 'justus') or die ('Unable to connect!');// select database for usemysql_select_db('sme_cms') or die ('Unable to select database!');$query = 'select * from auth ' ."where name='$user_name' " ." and pass=password('$pwd')"; $result = mysql_query($query); if (mysql_num_rows($result) >0 ) { // if they are in the database register the user id $HTTP_SESSION_VARS['valid_user'] = $user_name; }}if (isset($HTTP_SESSION_VARS['valid_user'])) { echo 'You are logged in as: '.$HTTP_SESSION_VARS['valid_user'].' <br />'; echo '<a href="logout.php">Log out</a><br />'; } else { if (isset($user_name)) { // if they've tried and failed to log in echo 'Could not log you in'; } else { // they have not tried to log in yet or have logged out echo 'You are not logged in.<br />'; } } ?> </body></html>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/19022-had-a-problem-with-sessionplease-help/#findComment-82277 Share on other sites More sharing options...
xux Posted August 29, 2006 Author Share Posted August 29, 2006 Thanks you to everybody,am going to try that out.I really appreciate everybody. Quote Link to comment https://forums.phpfreaks.com/topic/19022-had-a-problem-with-sessionplease-help/#findComment-82309 Share on other sites More sharing options...
xux Posted August 30, 2006 Author Share Posted August 30, 2006 Hi, The code stop giving me errors,but it refuse to log me in,just saying cannot be logged in even when the right user name and password was used.Please what do you think is wrong.Thanks Quote Link to comment https://forums.phpfreaks.com/topic/19022-had-a-problem-with-sessionplease-help/#findComment-82713 Share on other sites More sharing options...
wildteen88 Posted August 30, 2006 Share Posted August 30, 2006 You are using old super global variables, you should use the new superglobal variables which are$_POST instead of $HTTP_POST_VARS$_GET instead of $HTTP_GET_VARS$_SESSION instead of $HTTP_SESSION_VARS$_COOKIE instead of $HTTP_COOKIE_VARSAlso this code here:[code=php:0]else { if (isset($user_name)) { // if they've tried and failed to log in echo 'Could not log you in'; } else { // they have not tried to log in yet or have logged out echo 'You are not logged in.<br />'; }[/code]Is a little strange. You are checking to see if $user_name exists, and if it does you say you cannot be logged in.Shouldnt this[code=php:0]if (isset($user_name))[/code]be[code=php:0]if (!isset($user_name))[/code]Otherwise if the user fills in the form correctly and hits submits it always goona say '[i]Could not log you in[/i]'. With the latter code it now checks whether the $user_name var doesnt exist. Quote Link to comment https://forums.phpfreaks.com/topic/19022-had-a-problem-with-sessionplease-help/#findComment-82741 Share on other sites More sharing options...
xux Posted August 30, 2006 Author Share Posted August 30, 2006 Hi, Thanks.I will try that out.But am using php4,can I used the new variable?I appreciate it,see ya later. Quote Link to comment https://forums.phpfreaks.com/topic/19022-had-a-problem-with-sessionplease-help/#findComment-82901 Share on other sites More sharing options...
wildteen88 Posted August 30, 2006 Share Posted August 30, 2006 Yes the new superglobals where introduced in PHP 4.2. You should be able to use the new superglobals in PHP4.2 or greater Quote Link to comment https://forums.phpfreaks.com/topic/19022-had-a-problem-with-sessionplease-help/#findComment-82909 Share on other sites More sharing options...
xux Posted August 30, 2006 Author Share Posted August 30, 2006 Hi, After effecting the changes you suggested it is still outputing 'could not log in' despite using the right name and password.what do you think i can do,or is there another way to implement it?i see that you are a moderator,that shows you must be php guru,can you also help with an updating script into a mysql database using database?thanks Quote Link to comment https://forums.phpfreaks.com/topic/19022-had-a-problem-with-sessionplease-help/#findComment-82945 Share on other sites More sharing options...
wildteen88 Posted August 30, 2006 Share Posted August 30, 2006 Diod you read this bit of my post above:[quote]Also this code here:else { if (isset($user_name)) { // if they've tried and failed to log in echo 'Could not log you in'; } else { // they have not tried to log in yet or have logged out echo 'You are not logged in.<br />'; }Is a little strange. You are checking to see if $user_name exists, and if it does you say you cannot be logged in.Shouldnt thisif (isset($user_name))beif (!isset($user_name))Otherwise if the user fills in the form correctly and hits submits it always goona say 'Could not log you in'. With the latter code it now checks whether the $user_name var doesnt exist.[/quote] Quote Link to comment https://forums.phpfreaks.com/topic/19022-had-a-problem-with-sessionplease-help/#findComment-82948 Share on other sites More sharing options...
xux Posted August 30, 2006 Author Share Posted August 30, 2006 ok,maybe i should remove that portion of the code.or what do you think?thanks Quote Link to comment https://forums.phpfreaks.com/topic/19022-had-a-problem-with-sessionplease-help/#findComment-82958 Share on other sites More sharing options...
wildteen88 Posted August 30, 2006 Share Posted August 30, 2006 Swap if (isset($user_name))to if (!isset($user_name))notice the ! before isset Quote Link to comment https://forums.phpfreaks.com/topic/19022-had-a-problem-with-sessionplease-help/#findComment-82972 Share on other sites More sharing options...
xux Posted August 31, 2006 Author Share Posted August 31, 2006 Thanks, I tried that,but it is still reporting the same error.I will appreciate ur assistance.Thanks Quote Link to comment https://forums.phpfreaks.com/topic/19022-had-a-problem-with-sessionplease-help/#findComment-83537 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.