decon Posted March 9, 2015 Share Posted March 9, 2015 So, I'm kinda new to PHP I started learning it a couple months ago and I'm currently trying to make a login/register system with a user control panel, admin backend etc... I've got the registration part down I can insert users into the database, etc but I'm still sorta a noob to this. So basically I'm trying to check if the user is logged in using $_SESSION like everyone does, well mostly I think. Anyway here is the code I'm using for my file login_check.php: <?php session_start(); if ( isset( $_SESSION[ 'logged_in' ] && $_SESSION[ 'logged_in' ] == true ) ){ echo "You are logged in<br/>"; }else { echo "You are not logged in<br/>"; } ?> once I go to login_check.php on my website the page is completely blank, and as far as I'm aware a blank page in PHP means there is a error in the code. but I've tried to fix the errors, I've narrowed it down to being the 3rd line. Something is wrong with it, but I'm not sure what. Please help. Thanks guys. Quote Link to comment https://forums.phpfreaks.com/topic/295187-issue-with-checking-login-sessions/ Share on other sites More sharing options...
sford999 Posted March 9, 2015 Share Posted March 9, 2015 Try this <?php session_start(); if ($_SESSION['logged_in'] && $_SESSION['logged_in'] != ''){ echo "You are logged in<br/>"; }else { echo "You are not logged in<br/>"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/295187-issue-with-checking-login-sessions/#findComment-1507925 Share on other sites More sharing options...
maxxd Posted March 9, 2015 Share Posted March 9, 2015 Turn on error reporting at the top of your script: ini_set('display_errors',true); error_reporting(-1); These lines instruct php to print all errors and warnings to the screen, so you'll them instead just a blank white screen. Obviously you'll want to comment these lines out before you take your site live, but you should always have error reporting enabled while developing. Quote Link to comment https://forums.phpfreaks.com/topic/295187-issue-with-checking-login-sessions/#findComment-1507932 Share on other sites More sharing options...
mac_gyver Posted March 9, 2015 Share Posted March 9, 2015 your code has the closing ) for the isset(...) statement in the wrong place (at the end of the line), producing a php syntax error (Parse error: syntax error, unexpected '&&' (T_BOOLEAN_AND), expecting ',' or ')' in your_file on line 3). the closing ) for the isset() belongs after the $_SESSION[ 'logged_in' ] parameter - isset( $_SESSION[ 'logged_in' ] ) && .... you need to have php's error_reporting set to E_ALL and display_errors set to ON in the php.ini on your development system to get php to help you find these kind of errors. putting these settings into your code won't help with syntax errors in your main file since your code never runs when there is a syntax error and lines trying to change the settings aren't executed. @sford999, while your posted code is syntactically correct, by removing the isset() statement, it will throw php errors when the page is visited when not logged in. also, by just posting 'fixed' code, without any statement of what was wrong with the original code, the OP doesn't learn anything. Quote Link to comment https://forums.phpfreaks.com/topic/295187-issue-with-checking-login-sessions/#findComment-1507935 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.