Jump to content


Photo

Check boxes as a combonation lock????


  • Please log in to reply
2 replies to this topic

#1 thx1138

thx1138
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 31 May 2006 - 01:44 PM

OK, I have tried to fiqure out a way to do this with radio buttons, no luck.

Now I am setting it up with check boxes, I am not sure how to pass on two required variables
in order to make the "lock" work. I can easily make one check box be required to gain access,
however I cannot get two (Multiple) check boxes as in a combination to work?

here is part of the code:

Code:

<?php 
include("config.php"); 
$cookuser = $_COOKIE["cookuser"]; 
if($cookuser) { 
    if(($cookuser == $adminuser) or ($cookuser == $adminuser4)){ 
    echo("<title>BLABLA</title> 
 unlocked information then is displayed here...



Basically all this does is make it so my 1st or 4th check box allows users access to the BLABLA information.
How do I go about requiring BOTH 1st AND 4th being required? I have swithched the [!--coloro:#FF0000--][span style=\"color:#FF0000\"][!--/coloro--]or[!--colorc--][/span][!--/colorc--] to an [!--coloro:#FF0000--][span style=\"color:#FF0000\"][!--/coloro--]and[!--colorc--][/span][!--/colorc--] but that just lets either work....?


Thanks for any guidance... I know I am missing something fairly basic because I am a
worthless script kiddie! [img src=\"style_emoticons/[#EMO_DIR#]/unsure.gif\" style=\"vertical-align:middle\" emoid=\":unsure:\" border=\"0\" alt=\"unsure.gif\" /]

THX1138

#2 poirot

poirot
  • Members
  • PipPipPip
  • Advanced Member
  • 646 posts
  • LocationAustin, TX

Posted 31 May 2006 - 02:42 PM

It sounded like a fairly interesting idea, so I coded a function:

Just use checkCB(POSTED DATA, COMBINATION ARRAY)
It will return false if the posted data is not an array, or some checkbox that shouldn't be on is on (to avoid people from gaining access by selecting all boxes), or if some require checkbox is missed.

Otherwise, returns true.
I hope it's understanble. I also added an example.

<?php

function checkCB($posted, $match)
{
   if (!is_array($posted)) {
      return false;
   } else {
      foreach ($posted as $value) {
         $key = array_search((int) $value, $match);
         if ($key === false) return false;
         else $unset[] = $key;
      }

      foreach ($unset as $value) {
         unset($match[$value]);
      }
      return (!empty($match)) ? false : true;
   }
}

// Everything below this is part of the example.

$should_be_on = array(1, 4);

if (!empty($_POST['lock'])) {
   if (!checkCB($_POST['lock'], $should_be_on)) {
      echo 'Wrong Code';
   } else {
      echo 'Access Granted';
   }
}

?>

<form action="" method="post">
 <input type="checkbox" name="lock[]" value="1">
 <input type="checkbox" name="lock[]" value="2">
 <input type="checkbox" name="lock[]" value="3">
 <input type="checkbox" name="lock[]" value="4">
 <input type="submit" value="Test">
</form>

~ D Kuang

#3 neylitalo

neylitalo
  • Staff Alumni
  • Advanced Member
  • 1,854 posts
  • LocationMichigan, USA

Posted 31 May 2006 - 05:08 PM

instead of "or", use "&&" - like this.

if(($cookuser == $adminuser) && ($cookuser == $adminuser4)){

http://nealylitalo.net - My personal website, and home of The Netizen's Journal.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users