Jump to content

Check boxes as a combonation lock????


thx1138

Recommended Posts

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:

[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...[/code]


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
Link to comment
https://forums.phpfreaks.com/topic/10857-check-boxes-as-a-combonation-lock/
Share on other sites

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.

[code]<?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>[/code]

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.