I am a absolute beginner in PHP and I need some help with my first scipt.
I have an array like this:
$ids = array("test1", "testa", "test2", "testv");
This is my full code:
<?php
$ids = array("test1", "testa", "test2", "testv");
$id = $_GET['id'];
if($id == null){$done .= "Wrong ID";}
else if ($id == $ids[0])
{
$laenge = 8;
for($i=0;$i<$laenge;$i++){$rnd = rand(1,62);
if ($rnd <= 10){$rnd += 47;}else if($rnd <= 36){$rnd += 54;}
else{$rnd += 60; }
$done .= chr($rnd);
}
}?>
now I will check the input with an GET variable of the array ( script.php?id= ).
at example script.php?id=test1 <<< Works great because of ($id == $ids[0]) but how can I get it to work that only (all) the variables from my array ($ids) are accepted
at example:
script.php?id=test1 = ok
script.php?id=testa = ok
script.php?id=test2 = ok
script.php?id=testv = ok
script.php?id=bla = Not ok
I hope your understand my problem and can help me.
Thank you in advance 🙂
EDIT:
Thanks for your help but when i use this so
<?php
$ids = array("test1", "testa", "test2", "testv");
if(in_array($_GET['id'], $ids)
{
$laenge = 8;
for($i=0;$i<$laenge;$i++){$rnd = rand(1,62);
if ($rnd <= 10){$rnd += 47;}else if($rnd <= 36){$rnd += 54;}
else{$rnd += 60; }
$gutschein .= chr($rnd);
} else {
echo 'Wrong ID';
}
}?>
i become an whitepage, sorry im totay new in php
You can use
in_arrayto see if a value is in a given array.