Jump to content

Recommended Posts

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

[!--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]
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 anyway

cheers
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 1

Warning: 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 1

Warning: 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 1

then 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 0

Warning: 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
[!--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 1

Warning: 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 1

Warning: 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 1

then 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 0

Warning: 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 like

session.save_path = C:\Program Files\Apache Group\Apache2\sessions

The 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


This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.