PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, January 23, 2022

[FIXED] Operator "! " not working with "&&" operator

 January 23, 2022     codeigniter, php     No comments   

Issue

Following is my code:

<?php
$acl_test = "companies";
$act_test2 = "contractor";

if (!($this->acl->hasPermission($acl_test)) && ($this->acl->hasPermission($acl_test2))) {
    ?>

    <li <?php print ($selected == 'companies' || $selected == 'contractor') ? 'class="selected"' : ''; ?>>
        <a class="top-level" href="#">Clients</a>
        <ul>
            <li><a href="<?php print site_url('companies'); ?>">Company</a></li>
            <li><a href="<?php print site_url('contractors'); ?>">Contractor</a></li>
        </ul>
    </li>
<?php } ?>

Now, want I would like to do is basically, I am validating that logged in user has the permission to view the following link. This works fine if i put the check individually on each link. Although i any user has the one of the permission that he would be able to see the Clients link. Now, if any user does not have any permission to view link then he should not able to see the Clients link either. But something wrong with logical operation. Any suggestion?


Solution

Although if any user has the one of the permission that he would be able to see the Clients link. Now, if any user does not have any permission to view link then he should not able to see the Clients link either.

do you mean if any of that permission is true you will let the user see the link? if that's the case, why don't you try:

if($this->acl->hasPermission($acl_test) || $this->acl->hasPermission($acl_test2)){
     // do something
}


Answered By - Ceeee
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing