1

I have edited my question.., I have 10 users in my database table and the number may vary. In which only 3 users(It may be random) have to access the page given under if condition. The other users should be redirected to button.php page with a parameter. I have identified the users with $aces variable. So in if condition, I have specified only that 3 users with Not equal to condition. If the logged in user is in the 3, then he is able to access the followed page. Otherwise user should be redirected to button_page.php with a message that "You are not authorised to access this page". Now the '!=' operator doesn't work. if i use '==' operator for example of 3 users it works fine. How to use '!=' operator in if condition??

session_start();
$aces='';
if(!isset($_SESSION['ID'])){        
    header("Location:login.php");   
}
$aces=$_SESSION['Access'];    
if($aces != 1 || $aces != 2 || $aces != 0){                                     
    header("Location:button_page.php?m");
    exit;
}
Lelio Faieta
  • 6,457
  • 7
  • 40
  • 74
Vijay
  • 25
  • 4
  • 1
    `||` will work if any of the condition is true, may be you need `&&` – Rahul Jun 11 '19 at 07:07
  • `but in if condition it is not working.?` what do you mean by that? – Alive to die - Anant Jun 11 '19 at 07:08
  • what is the value of `$aces` you are trying to compare? – Rahul Jun 11 '19 at 07:10
  • @DrakulaPredator,, Hi.., $aces gets an integer value. I have also tried with '!=' operator. There also it does not work. – Vijay Jun 11 '19 at 07:13
  • What values $aces are carrying? Let us know, what exactly you are trying to achieve? – Rahul Jun 11 '19 at 07:15
  • @KIKOSoftware.., Hi there.., I have also tried with '!=' operator. There also it does not work. $aces variable gets an integer variable. – Vijay Jun 11 '19 at 07:17
  • @AlivetoDie.., Hi there.., with "In if condition" I mean that , Outside if condition the integer value of $aces is displaying . but inside of if condition it is not comparing and it seems to have data type comparison problem.. I dont know the actual problem.. – Vijay Jun 11 '19 at 07:22
  • @Vijay i have added solution for that also in my answer – Alive to die - Anant Jun 11 '19 at 07:26
  • @DrakulaPredator, $aces gets the values of 0-10., and if the value of $aces is above 2 (>2) I want to pass the if condition and run the code follows. otherwise if $aces gets the values 0,1,2 it should redirect to button_page with a parameter m – Vijay Jun 11 '19 at 07:27
  • The condition would only be false if `$aces` was `1`, `2` *and* `0` *at the same time*… – deceze Jun 11 '19 at 07:31
  • @Vijay no one able to exactly understand what you are trying to do? Please explain properly – Alive to die - Anant Jun 11 '19 at 08:20
  • Just to make this really explicit: you're testing whether the variable *is not 1 or is not 2 [..]*. Well, it can't be 1 *and* 2 at the same time, so at least one of those conditions must be true always. Read the duplicate. – deceze Jun 11 '19 at 08:24

0 Answers0