Jump to content

Calculating checkbox values


danieljgraham

Recommended Posts

Hi There,

 

I just wanted to share a really cool way of managing check boxes. For instance you could use them for user access functions etc

 

For you to read the values in PHP, this returns a true or false (1 or 0)

 


      public function checkAccess($required) { // The value of the box your after....e.g......64
            $m_access = $_SESSION['login_Access']; // This is where you store the checkbox value
            if ($required == 1 ) {
                  if($m_access & $required) {
                        return true;
                  }
            } else {			
                  if(($m_access & $required) / $required == 1) {
                        return true;
                  }
            }
      return false;
      }

 

or

 


      if((1024 & 64) / 64 == 1) {
            return true;
      }


 

This function will always return a unique value as per the box checked.

 

Hope people find it useful.

 

Daniel

 

[attachment deleted by admin]

Link to comment
https://forums.phpfreaks.com/topic/212591-calculating-checkbox-values/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.