Forum Moderators: coopster
function select_menu(){
echo '<select name="files">';
$count = "0";
$getDir = opendir("./thingy"); # Enter here the directory to read the contents of
while($filename = readdir($getDir)) {
if ($filename[0]!= "." && $filename[0]!= ".." ) {
echo "<option value=\"$filename\">$filename</option>";
$count++;
}
}
echo '</select>';
closedir($getDir);
}
select_menu();
now what i want to do is this...
$userinput = $_POST['data_from_form'];
if ( $userinput = "any of the documents listed by the function" ) {
do something; }
else { do something else }
obviously the above will not work
i don't know what to replace the Any Of The Documents with
i don't even think i'm using the right statements
please tell me if i'm not being clear about what i want to do
any help appreciated
you'd probably be best to change the select_menu() function slightly so that it returns an array instead of a fully formatted html select drop down.
something like
function select_menu()
{
$arr_files = array(); // initialise the array
$count = "0";
$getDir = opendir("./thingy");
while($filename = readdir($getDir))
{
if ($filename[0]!= "." && $filename[0]!= ".." )
{
array_push($arr_files, $filename); // add each filename to the array
$count++;
}
}
closedir($getDir);
return $arr_files; //
}
then when you call select_menu() assign it straight a variable:
$array_of_files = select_menu();
and you have a ready made array of all your filenames. you can either loop through it spitting out html forms or comparing if/else values. your previous function only made an html select menu, which limits your options for further 'fun' with the filenames.
understanding arrays and looping through them is one of THE most useful php commands. google for "php array tutorials" there's loads out there.
good luck
when i call the array to see if a user's post equals ANY of the entries in the array, is it as simple as going...
if ( $userinput == $array ) { do this; }
?
i will still search google for a tutorial on arrays
thanks for the help again
foreach() would be the one to use
foreach ($arr_files as $k)
{
// now put code to test against $k
}
foreach allows you to loop through the array, doing something with each of the values.
($arr_files as $k) means you are telling foreach() to put the first value of $arr_files into the variable $k (you can choose $x, $y, $z - it's up to you).
the foreach() runs as many time as you have items in your array, and each time it assigns the next value in the array to $k. that way you loop through testing each value.
so in your case it would be something like
foreach ($arr_files as $k)
{
if ($userinput == $k)
{
// do something
}
}
or to spit out an html form
foreach ($arr_files as $k)
{
echo '<option value="' . $k . '">' . $k . '</option>';
}
(you'd have to add an opening and closing select tags for it to work).
good luck
here's the code
$adminRoot = "admin/";
$activityFile = $adminRoot."activity.txt";
$ipAddress = gethostbyaddr($_SERVER['REMOTE_ADDR']);
$banStateFile = $adminRoot."banState.txt";
$banState = file_get_contents($banStateFile);
if ($banState == "1") {
$blockBanned = array();
$count = "0";
$getDir = opendir($adminRoot."banned");
while($filename = readdir($getDir)) {
if ($filename[0]!= "." && $filename[0]!= "..") {
array_push($blockBanned, $filename);
$count++; }
}
closedir($getDir);
return $blockBanned;
foreach ($blockBanned as $k) {
if ($ipAddress == $k) {
$activityContents = file_get_contents($activityFile);
$newActivityContents = $doDate." - ".$ipAddress." - Banned user loaded page<BR>\r".$activityContents;
$openActivity = fopen($activityFile,"w");
fwrite($openActivity,$newActivityContents);
fclose($openActivity);
include("includes/header.php");
echo "<BR><BR>You cannot participate in this chat room<BR>because the owner has banned your ip.";
include("includes/footer.php");
exit(); }
}
}
there is no function definition in the above code, nor a call to an existing one, so the return line is obsolete.
this line:
if ($filename[0]!= "." && $filename[0]!= "..")
also has no meaning because the [0] doesn't refer to anything - that's what the $count value is for.
it would really help to read up on arrays and looping through them, then you'll be able to solve it easily yourself.
good luck