andrew6607 Posted October 4, 2007 Share Posted October 4, 2007 Hello im getting a error with sessions here it is Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at C:\xampp\htdocs\newsite\member.php:6) in C:\xampp\htdocs\newsite\member.php on line 24 Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\xampp\htdocs\newsite\member.php:6) in C:\xampp\htdocs\newsite\member.php on line 24 Welcome And here is the code im using <?php session_start(); // store session data $_SESSION['username']; ?> <?php //retrieve session data echo "Welcome". $_SESSION['username']; ?> PLEASE HELP!! Quote Link to comment https://forums.phpfreaks.com/topic/71755-solved-sessions/ Share on other sites More sharing options...
pocobueno1388 Posted October 4, 2007 Share Posted October 4, 2007 Are you sure you don't have a file included above that script called member.php? If you do, make sure you don't already have session_start already called in that file. Quote Link to comment https://forums.phpfreaks.com/topic/71755-solved-sessions/#findComment-361355 Share on other sites More sharing options...
andrew6607 Posted October 4, 2007 Author Share Posted October 4, 2007 Nope I dont know whats going on ill send ya the code of the script <?php $usernamea=$_POST['username']; $title=$usernamea; ?> <title> Welcome <?php echo $title; ?>! </title> <?php include_once("includes/config.php"); mysql_select_db($data,$connect) or die ("Cannot Connect to Database Server"); $username=$_POST['username']; $password=$_POST['password']; // Connections $sql="SELECT * FROM users WHERE username='$username' && password='$password'"; $query=mysql_query($sql); $row=mysql_fetch_assoc($query); $totalRow=mysql_num_rows($query); // If username is correct if ($username = $row['username']) { // If password is correct if ($password = $row['password']) { ?> <?php session_start(); session_register('user_id'); // store session data $_SESSION['username']; //retrieve session data echo "Welcome". $_SESSION['username']; ?> <?php } else { echo "Password is Incorrect! <a href='index.php'>Try Again</a>"; } } else { echo "Wrong Password or the User does not exist! <a href='index.php'>Try Again</a>"; } mysql_free_result($query); ?> Quote Link to comment https://forums.phpfreaks.com/topic/71755-solved-sessions/#findComment-361363 Share on other sites More sharing options...
Crew-Portal Posted October 4, 2007 Share Posted October 4, 2007 You Are declaring session_register(); Before your session_register. Try::: <?php session_start(); $usernamea=$_POST['username']; $title=$usernamea; ?> <title> Welcome <?php echo $title; ?>! </title> <?php require_once("includes/config.php"); mysql_select_db($data,$connect) or die ("Cannot Connect to Database Server"); $username=$_POST['username']; $password=$_POST['password']; // Connections $sql="SELECT * FROM users WHERE username='$username' && password='$password'"; $query=mysql_query($sql); $row=mysql_fetch_assoc($query); $totalRow=mysql_num_rows($query); // If username is correct if ($username = $row['username']) { // If password is correct if ($password = $row['password']) { ?> <?php session_register('user_id'); // store session data $_SESSION['username']; //retrieve session data echo "Welcome". $_SESSION['username']; ?> <?php } else { echo "Password is Incorrect! <a href='index.php'>Try Again</a>"; if (session_is_registered('username'){ session_unregister('username') } } } else { echo "Wrong Password or the User does not exist! <a href='index.php'>Try Again</a>"; if (session_is_registered('username'){ session_unregister('username') } } mysql_free_result($query); ?> Hope this helps Andrew? Quote Link to comment https://forums.phpfreaks.com/topic/71755-solved-sessions/#findComment-361371 Share on other sites More sharing options...
Crew-Portal Posted October 4, 2007 Share Posted October 4, 2007 Oops sorry error in my code. Try: <?php session_start(); $usernamea=$_POST['username']; $title=$usernamea; ?> <title> Welcome <?php echo $title; ?>! </title> <?php require_once("includes/config.php"); mysql_select_db($data,$connect) or die ("Cannot Connect to Database Server"); $username=$_POST['username']; $password=$_POST['password']; // Connections $sql="SELECT * FROM users WHERE username='$username' && password='$password'"; $query=mysql_query($sql); $row=mysql_fetch_assoc($query); $totalRow=mysql_num_rows($query); // If username is correct if ($username = $row['username']) { // If password is correct if ($password = $row['password']) { ?> <?php session_register('user_id'); // store session data $_SESSION['username']; //retrieve session data echo "Welcome". $_SESSION['username']; ?> <?php } else { echo "Password is Incorrect! <a href='index.php'>Try Again</a>"; if (session_is_registered('username'){ session_unregister('username'); } } } else { echo "Wrong Password or the User does not exist! <a href='index.php'>Try Again</a>"; if (session_is_registered('username'){ session_unregister('username'); } } mysql_free_result($query); ?> Cuase you get a: Parse error: syntax error, unexpected '{' in C:\xampp\htdocs\newsite\member.php on line 35 Quote Link to comment https://forums.phpfreaks.com/topic/71755-solved-sessions/#findComment-361375 Share on other sites More sharing options...
pocobueno1388 Posted October 4, 2007 Share Posted October 4, 2007 It's because session_start() has to be called at the very top of your script. Quote Link to comment https://forums.phpfreaks.com/topic/71755-solved-sessions/#findComment-361385 Share on other sites More sharing options...
Crew-Portal Posted October 4, 2007 Share Posted October 4, 2007 I already made that mod in the scripts just above you. lolz Quote Link to comment https://forums.phpfreaks.com/topic/71755-solved-sessions/#findComment-361388 Share on other sites More sharing options...
pocobueno1388 Posted October 4, 2007 Share Posted October 4, 2007 Oops, sorry...I didn't see that Quote Link to comment https://forums.phpfreaks.com/topic/71755-solved-sessions/#findComment-361390 Share on other sites More sharing options...
Crew-Portal Posted October 4, 2007 Share Posted October 4, 2007 Thats no problem. I was talkin' to the guy on MSN (Andrew I mean) And I belive he got his problem fixed. But I guess we'll wait till tommorrow for a response Quote Link to comment https://forums.phpfreaks.com/topic/71755-solved-sessions/#findComment-361398 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.