wkdw1ll1ams Posted September 19, 2011 Share Posted September 19, 2011 i got my user login and register working with my sql but now if a non logged in user tries to access the shoutbox i want it to redirect them to the register page. <?PHP session_start(); if (!(isset($_SESSION['login']) && $_SESSION['login'] != '')) { header ("Location: /login/main.php"); } ?> im using that code but even if im logged in, it redirects me to the register page? my main site is on the root of the site. the login page and the logged in page is in "/login/ Quote Link to comment https://forums.phpfreaks.com/topic/247468-user-is-online/ Share on other sites More sharing options...
xyph Posted September 19, 2011 Share Posted September 19, 2011 print_r( $_SESSION ) to verify your inputs are what you expect them to be. You should also verify the logic in your if() statement. Quote Link to comment https://forums.phpfreaks.com/topic/247468-user-is-online/#findComment-1270814 Share on other sites More sharing options...
ninjeh Posted September 20, 2011 Share Posted September 20, 2011 Your NOT operator, exclamation point, is on the wrong side of the parentheses. Also there is no space between the session_start(); and the initial php tag, but I am guessing that's the way it was copied and pasted. Also, you can eliminate one of the parentheses as there are not multiple logic scenarios in your if statement. Before: <?PHPsession_start();if (!(isset($_SESSION['login']) && $_SESSION['login'] != '')) {header ("Location: /login/main.php");}?>() After <?PHP session_start(); if (!isset($_SESSION['login']) && $_SESSION['login'] != '') {header ("Location: /login/main.php");}?>() Quote Link to comment https://forums.phpfreaks.com/topic/247468-user-is-online/#findComment-1270852 Share on other sites More sharing options...
Psycho Posted September 20, 2011 Share Posted September 20, 2011 Your NOT operator, exclamation point, is on the wrong side of the parentheses. Also there is no space between the session_start(); and the initial php tag, but I am guessing that's the way it was copied and pasted. Also, you can eliminate one of the parentheses as there are not multiple logic scenarios in your if statement. No, his NOT operator is correct for what he has, but the whole construction of the condition is kinda backwards IMHO. Also, not sure what you are saying about no space between the opening PHP tag and the session_start() - they are on two separate lines from what I see. Anyway, I agree with xyph do a print_r(0 to check the session variable. I would also change the logic to be easier to interpret. <?php session_start(); if (!isset($_SESSION['login']) || $_SESSION['login'] == '') { //Debug line echo "Auth check failed. Session vars: " . print_r($_SESSION, true); //header ("Location: /login/main.php"); } echo "Auth check passed"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/247468-user-is-online/#findComment-1270868 Share on other sites More sharing options...
wkdw1ll1ams Posted September 20, 2011 Author Share Posted September 20, 2011 ive attached the login files in a zip archive for you to understand more of how the code works. [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/247468-user-is-online/#findComment-1270909 Share on other sites More sharing options...
Psycho Posted September 20, 2011 Share Posted September 20, 2011 ive attached the login files in a zip archive for you to understand more of how the code works. Have you verified the content of $_SESSION like we suggested? What were the results. Don't just throw code at us expecting us to fix it. My goal on this forum is to help people and in that process to learn to solve problems on their own. A big part of that is learning to debug your code. When something does not work the way you expect then you need to verify the inputs and outputs. Since your if() statemetns seems to be not working you need to validate the values that are being compared in that if condition. Quote Link to comment https://forums.phpfreaks.com/topic/247468-user-is-online/#findComment-1271021 Share on other sites More sharing options...
wkdw1ll1ams Posted September 20, 2011 Author Share Posted September 20, 2011 im not firmiliar with $_session but i just get an error: Notice: Undefined variable: _SESSION in C:\xampp\htdocs\tvshows.php on line 2 Quote Link to comment https://forums.phpfreaks.com/topic/247468-user-is-online/#findComment-1271027 Share on other sites More sharing options...
Psycho Posted September 20, 2011 Share Posted September 20, 2011 im not firmiliar with $_session but i just get an error: Notice: Undefined variable: _SESSION in C:\xampp\htdocs\tvshows.php on line 2 Are you trying to use $_SESSION before you start the session (i.e. did you put print_r($_SESSION); before session_start())? Try the code I posted and state what the results are. Quote Link to comment https://forums.phpfreaks.com/topic/247468-user-is-online/#findComment-1271055 Share on other sites More sharing options...
wkdw1ll1ams Posted September 20, 2011 Author Share Posted September 20, 2011 Parse error: syntax error, unexpected T_STRING in C:\xampp\htdocs\index.php on line 3 php is a pain Quote Link to comment https://forums.phpfreaks.com/topic/247468-user-is-online/#findComment-1271191 Share on other sites More sharing options...
Pikachu2000 Posted September 20, 2011 Share Posted September 20, 2011 It would appear the problem is on or near line 3. Quote Link to comment https://forums.phpfreaks.com/topic/247468-user-is-online/#findComment-1271197 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.