thx1138 Posted May 31, 2006 Share Posted May 31, 2006 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 Quote Link to comment https://forums.phpfreaks.com/topic/10857-check-boxes-as-a-combonation-lock/ Share on other sites More sharing options...
poirot Posted May 31, 2006 Share Posted May 31, 2006 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]<?phpfunction 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] Quote Link to comment https://forums.phpfreaks.com/topic/10857-check-boxes-as-a-combonation-lock/#findComment-40572 Share on other sites More sharing options...
neylitalo Posted May 31, 2006 Share Posted May 31, 2006 instead of "or", use "&&" - like this.[code]if(($cookuser == $adminuser) && ($cookuser == $adminuser4)){[/code] Quote Link to comment https://forums.phpfreaks.com/topic/10857-check-boxes-as-a-combonation-lock/#findComment-40623 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.