essjay_d12 Posted March 14, 2006 Share Posted March 14, 2006 I'm trying a login session...but the following code is producing an error "Parse error: parse error, unexpected '{' " and its the first one the error is pointing at.[code]<?php if (isset($_SESSION['username']) {echo "Welcome";echo $_SESSION['username'];}if (unset($_SESSION['username']) {echo "Please Sign in";} ?>[/code]then there is also the following at the beginning of the page[code]<?php session_start(); ?>[/code]What have I done wrong?Thanks Link to comment https://forums.phpfreaks.com/topic/4924-unexpected-in-session-code/ Share on other sites More sharing options...
obsidian Posted March 14, 2006 Share Posted March 14, 2006 you're missing your closing parenthesis on your if statement:[code]// change this:if (isset($_SESSION['username']) {// to this:if (isset($_SESSION['username'])) {[/code]btw, you'll get the same error on your second if statement, too. Link to comment https://forums.phpfreaks.com/topic/4924-unexpected-in-session-code/#findComment-17345 Share on other sites More sharing options...
essjay_d12 Posted March 14, 2006 Author Share Posted March 14, 2006 thanks i changed both now it says ...Parse error: parse error, unexpected T_UNSET?? Link to comment https://forums.phpfreaks.com/topic/4924-unexpected-in-session-code/#findComment-17347 Share on other sites More sharing options...
obsidian Posted March 14, 2006 Share Posted March 14, 2006 [!--quoteo(post=354873:date=Mar 14 2006, 08:37 AM:name=Essjay_d12)--][div class=\'quotetop\']QUOTE(Essjay_d12 @ Mar 14 2006, 08:37 AM) [snapback]354873[/snapback][/div][div class=\'quotemain\'][!--quotec--]thanks i changed both now it says ...Parse error: parse error, unexpected T_UNSET??[/quote]that's because unset() doesn't return any value, and your if statement requires some sort of argument in it. if you're wanting to see if there is a username set and do one or the other, you'd be better off just using an else:[code]if (isset($_SESSION['username'])) { echo "Welcome, $_SESSION[username]!";} else { echo "Please sign in";}[/code] Link to comment https://forums.phpfreaks.com/topic/4924-unexpected-in-session-code/#findComment-17349 Share on other sites More sharing options...
redbullmarky Posted March 14, 2006 Share Posted March 14, 2006 change this:[code]if (unset($_SESSION['username']) {[/code]to this[code]if (!isset($_SESSION['username'])) {[/code][b]EDIT:[/b] ooops same time post again......in which case, the way obsidian suggested is much better for what you're after anywaycheers Link to comment https://forums.phpfreaks.com/topic/4924-unexpected-in-session-code/#findComment-17352 Share on other sites More sharing options...
essjay_d12 Posted March 14, 2006 Author Share Posted March 14, 2006 yeah both worked .....but now further errors relating to the session at the beginning....Warning: session_start(): open(/tmp\sess_99a3b92d86e67afe762f29c6b156dfe4, O_RDWR) failed: No such file or directory (2) in C:\Program Files\Apache Group\Apache2\htdocs\dvdreviewer\LoginTest.php on line 1Warning: session_start(): Cannot send session cookie - headers already sent by (output started at C:\Program Files\Apache Group\Apache2\htdocs\dvdreviewer\LoginTest.php:1) in C:\Program Files\Apache Group\Apache2\htdocs\dvdreviewer\LoginTest.php on line 1Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at C:\Program Files\Apache Group\Apache2\htdocs\dvdreviewer\LoginTest.php:1) in C:\Program Files\Apache Group\Apache2\htdocs\dvdreviewer\LoginTest.php on line 1then it displays it correctly ... saying 'Please Sign in'then further errors....Warning: Unknown(): open(/tmp\sess_99a3b92d86e67afe762f29c6b156dfe4, O_RDWR) failed: No such file or directory (2) in Unknown on line 0Warning: Unknown(): Failed to write session data (files). Please verify that the current setting of session.save_path is correct (/tmp) in Unknown on line 0 Link to comment https://forums.phpfreaks.com/topic/4924-unexpected-in-session-code/#findComment-17353 Share on other sites More sharing options...
webwiese Posted March 14, 2006 Share Posted March 14, 2006 [!--quoteo(post=354879:date=Mar 14 2006, 03:02 PM:name=Essjay_d12)--][div class=\'quotetop\']QUOTE(Essjay_d12 @ Mar 14 2006, 03:02 PM) [snapback]354879[/snapback][/div][div class=\'quotemain\'][!--quotec--]yeah both worked .....but now further errors relating to the session at the beginning....Warning: session_start(): open(/tmp\sess_99a3b92d86e67afe762f29c6b156dfe4, O_RDWR) failed: No such file or directory (2) in C:\Program Files\Apache Group\Apache2\htdocs\dvdreviewer\LoginTest.php on line 1Warning: session_start(): Cannot send session cookie - headers already sent by (output started at C:\Program Files\Apache Group\Apache2\htdocs\dvdreviewer\LoginTest.php:1) in C:\Program Files\Apache Group\Apache2\htdocs\dvdreviewer\LoginTest.php on line 1Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at C:\Program Files\Apache Group\Apache2\htdocs\dvdreviewer\LoginTest.php:1) in C:\Program Files\Apache Group\Apache2\htdocs\dvdreviewer\LoginTest.php on line 1then it displays it correctly ... saying 'Please Sign in'then further errors....Warning: Unknown(): open(/tmp\sess_99a3b92d86e67afe762f29c6b156dfe4, O_RDWR) failed: No such file or directory (2) in Unknown on line 0Warning: Unknown(): Failed to write session data (files). Please verify that the current setting of session.save_path is correct (/tmp) in Unknown on line 0[/quote]Hi from Germany,the first error message seems to be php.ini - config problem. you're using windows, the standard php.ini (\tmp) for session dir is no usable under windows. you have do create a directory and add this to your php.ini likesession.save_path = C:\Program Files\Apache Group\Apache2\sessionsThe second and third error message due to the first error message, this was an output and session_start() must be set before any screen output.Hope it will work,webwiese Link to comment https://forums.phpfreaks.com/topic/4924-unexpected-in-session-code/#findComment-17362 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.