Asheeown Posted January 28, 2007 Share Posted January 28, 2007 [code]if(!$_SESSION['LoggedIn']) { echo "<p><strong>Sorry you must be logged in to view this page.</strong></p>"; die();} elseif($_SESSION['UserGroup'] > "1") { echo "<p><strong>Sorry you have insufficient privileges to view this page, if you feel this information is incorrect please contact the administrator.</strong></p>"; die();}[/code]Now the LoggedIn Session part works, however when I am logged in it says my permissions are not sufficient which is incorrect I even "echoed" the session out right before the die command and it came up as 2 Link to comment https://forums.phpfreaks.com/topic/36012-solved-if-statement-wrong/ Share on other sites More sharing options...
Asheeown Posted January 28, 2007 Author Share Posted January 28, 2007 Actually I figured out what it is but not a solution. It's the elseif, I reversed them and it says I'm not logged in. Link to comment https://forums.phpfreaks.com/topic/36012-solved-if-statement-wrong/#findComment-170839 Share on other sites More sharing options...
Tandem Posted January 28, 2007 Share Posted January 28, 2007 Hmmmmm. Try setting the type of the session variable. e.g.[code]settype($_SESSION['UserGroup'], "float");[/code]I don't think you need quotes around the 1 either. Link to comment https://forums.phpfreaks.com/topic/36012-solved-if-statement-wrong/#findComment-170840 Share on other sites More sharing options...
Asheeown Posted January 28, 2007 Author Share Posted January 28, 2007 I use [quote]$_SESSION['UserGroup'] > "1"[/quote]On my homepage to determine to show the Admin Section button or not so i know its right Link to comment https://forums.phpfreaks.com/topic/36012-solved-if-statement-wrong/#findComment-170841 Share on other sites More sharing options...
fert Posted January 28, 2007 Share Posted January 28, 2007 well with [code]$_SESSION['UserGroup'] > "1"[/code]That's saying if the value of $_SESSION['UserGroup'] is greater than the ascii value of 1 which I believe is 49 Link to comment https://forums.phpfreaks.com/topic/36012-solved-if-statement-wrong/#findComment-170842 Share on other sites More sharing options...
Asheeown Posted January 28, 2007 Author Share Posted January 28, 2007 I'm talking about in the IF statement...I know this If statement works just in parts why not together? Link to comment https://forums.phpfreaks.com/topic/36012-solved-if-statement-wrong/#findComment-170843 Share on other sites More sharing options...
fert Posted January 28, 2007 Share Posted January 28, 2007 And that's what I'm talk about change "1" to 1 Link to comment https://forums.phpfreaks.com/topic/36012-solved-if-statement-wrong/#findComment-170844 Share on other sites More sharing options...
Asheeown Posted January 28, 2007 Author Share Posted January 28, 2007 Look I know that way doesn't work thats what I've been saying, and anyway I'm using the if statement[code]if($_SESSION['UserGroup'] > "1")[/code]On a different page and it works fine Link to comment https://forums.phpfreaks.com/topic/36012-solved-if-statement-wrong/#findComment-170848 Share on other sites More sharing options...
Tandem Posted January 28, 2007 Share Posted January 28, 2007 It's bad coding practice. You should change that too. Link to comment https://forums.phpfreaks.com/topic/36012-solved-if-statement-wrong/#findComment-170849 Share on other sites More sharing options...
Asheeown Posted January 28, 2007 Author Share Posted January 28, 2007 I'm not changing anything it works fine, I'm just trying to figure out why my first IF statement doesn't work Link to comment https://forums.phpfreaks.com/topic/36012-solved-if-statement-wrong/#findComment-170852 Share on other sites More sharing options...
Tandem Posted January 28, 2007 Share Posted January 28, 2007 Try empty rather than !i.e (!empty($variable)) { Link to comment https://forums.phpfreaks.com/topic/36012-solved-if-statement-wrong/#findComment-170855 Share on other sites More sharing options...
Asheeown Posted January 28, 2007 Author Share Posted January 28, 2007 Read what the question asks...$_SESSION['UserGroup'] needs to be greater than "1" or else it dies...not empty the first part(the logged in part) works fine Link to comment https://forums.phpfreaks.com/topic/36012-solved-if-statement-wrong/#findComment-170858 Share on other sites More sharing options...
Asheeown Posted January 28, 2007 Author Share Posted January 28, 2007 Any idea why this would work anywhere else and not inside a function when the $_SESSION['UserGroup'] is set and it is greater than 1 Link to comment https://forums.phpfreaks.com/topic/36012-solved-if-statement-wrong/#findComment-170906 Share on other sites More sharing options...
trq Posted January 28, 2007 Share Posted January 28, 2007 Integers can not be surrounded in quotes.[code=php:0]} elseif($_SESSION['UserGroup'] > 1) {[/code] Link to comment https://forums.phpfreaks.com/topic/36012-solved-if-statement-wrong/#findComment-170917 Share on other sites More sharing options...
Asheeown Posted January 28, 2007 Author Share Posted January 28, 2007 i already tried that Link to comment https://forums.phpfreaks.com/topic/36012-solved-if-statement-wrong/#findComment-170930 Share on other sites More sharing options...
trq Posted January 28, 2007 Share Posted January 28, 2007 Post your current code then, I don't see any problem. Link to comment https://forums.phpfreaks.com/topic/36012-solved-if-statement-wrong/#findComment-170931 Share on other sites More sharing options...
Asheeown Posted January 28, 2007 Author Share Posted January 28, 2007 I made it into one so it's more efficient:[code] if(!$_SESSION['LoggedIn'] && $_SESSION['UserGroup'] > 1) { echo "<p><strong>Sorry you have insufficient privileges to view this page, if you feel this information is incorrect please contact the administrator.</strong></p>"; die();}[/code]$_SESSION['LoggedIn'] = 1 and $_SESSION['UserGroup'] = 2Now it just doesnt work Link to comment https://forums.phpfreaks.com/topic/36012-solved-if-statement-wrong/#findComment-170935 Share on other sites More sharing options...
redarrow Posted January 28, 2007 Share Posted January 28, 2007 try this ok[code]<?phpif( (!$_SESSION['LoggedIn'] )&& (!$_SESSION['UserGroup'] > 1) ) { echo "<p><strong>Sorry you have insufficient privileges to view this page, if you feel this information is incorrect please contact the administrator.</strong></p>"; die();}?>[/code] Link to comment https://forums.phpfreaks.com/topic/36012-solved-if-statement-wrong/#findComment-170939 Share on other sites More sharing options...
trq Posted January 28, 2007 Share Posted January 28, 2007 [code=php:0]if ((!$_SESSION['LoggedIn']) || (!$_SESSION['UserGroup'] > 1) ) {[/code] Link to comment https://forums.phpfreaks.com/topic/36012-solved-if-statement-wrong/#findComment-170943 Share on other sites More sharing options...
Asheeown Posted January 28, 2007 Author Share Posted January 28, 2007 Perfect Thorpe I didn't think to use || I used && and it said I was logged in everytime but it works perfect now, thanks Link to comment https://forums.phpfreaks.com/topic/36012-solved-if-statement-wrong/#findComment-170944 Share on other sites More sharing options...
redarrow Posted January 28, 2007 Share Posted January 28, 2007 thorpe dosent the || mean or and this means and &&cheers. Link to comment https://forums.phpfreaks.com/topic/36012-solved-if-statement-wrong/#findComment-170945 Share on other sites More sharing options...
trq Posted January 28, 2007 Share Posted January 28, 2007 [quote author=redarrow link=topic=124359.msg515199#msg515199 date=1169957194]thorpe dosent the || mean or and this means and &&cheers.[/quote]Exactly. Link to comment https://forums.phpfreaks.com/topic/36012-solved-if-statement-wrong/#findComment-170947 Share on other sites More sharing options...
redarrow Posted January 28, 2007 Share Posted January 28, 2007 cheers m8 Link to comment https://forums.phpfreaks.com/topic/36012-solved-if-statement-wrong/#findComment-170948 Share on other sites More sharing options...
Jessica Posted January 28, 2007 Share Posted January 28, 2007 "when I am logged in it says my permissions are not sufficient which is incorrect I even "echoed" the session out right before the die command and it came up as 2"2 > 1 - therefore, the code works fine. You just don't understand what > means. Link to comment https://forums.phpfreaks.com/topic/36012-solved-if-statement-wrong/#findComment-170953 Share on other sites More sharing options...
redarrow Posted January 28, 2007 Share Posted January 28, 2007 more then >less then < Link to comment https://forums.phpfreaks.com/topic/36012-solved-if-statement-wrong/#findComment-170955 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.