Solved

Combo Boxes...

Posted on 2003-11-17
11
345 Views
Last Modified: 2006-11-17
The following code works fine, BUT for the combo box (<select>), I want wateva is the variable $filename to be put first in the combo box and all the other files listed afterwards.... at the moment, it just does it in alphabeticall order...

$dir = opendir('/newusers/bja/');

echo '<select onClick="location.href=\'index.php?filename=\'+this.options[this.selectedIndex].text;">'."\n";

while ($file = readdir($dir))
{
if ((($file != '.')&&($file != '..')&&(filetype($file)=='file')))
{
echo '<option>'.$file."</option>\n";
}
}

echo "</select>\n";

closedir($dir)

Thankyou :)
0
Comment
Question by:ChrisAnnable
  • 6
  • 5
11 Comments
 
LVL 13

Expert Comment

by:lozloz
ID: 9763175
hi,

<?

$dir = opendir('/newusers/bja/');

echo '<select onClick="location.href=\'index.php?filename=\'+this.options[this.selectedIndex].text;">'."\n";
if($_GET["filename"]) {
  echo "<option>$filename</option>\n";
}
while ($file = readdir($dir)) {
  if ((($file != '.')&&($file != '..')&&(filetype($file)=='file'))) {
    if($file != $_GET["filename"]) {
      echo "<option>$file</option>\n";
    }
  }
}
echo "</select>\n";

closedir($dir);

?>

i think this is what you want

loz
0
 

Author Comment

by:ChrisAnnable
ID: 9763373
Exactly want i want :)

Only thing is, can i make it so, it won't put the file if itselft?

Thanks
0
 
LVL 13

Expert Comment

by:lozloz
ID: 9763392
how do you mean exactly? do you mean not put the file in the combo box at all? if so you want to remove the following lines:

if($_GET["filename"]) {
  echo "<option>$filename</option>\n";
}

loz
0
 

Author Comment

by:ChrisAnnable
ID: 9763461
No, i mean the file that is using the script...
0
 
LVL 13

Accepted Solution

by:
lozloz earned 100 total points
ID: 9763539
<?

$dir = opendir('/newusers/bja/');

$thispage = explode("/", $_SERVER["PHP_SELF"]);
$countpage = count($thispage) - 1;
$page = $thispage[$countpage];
echo '<select onClick="location.href=\'index.php?filename=\'+this.options[this.selectedIndex].text;">'."\n";
if($_GET["filename"]) {
  echo "<option>$filename</option>\n";
}
while ($file = readdir($dir)) {
  if ((($file != '.')&&($file != '..')&&(filetype($file)=='file'))) {
    if($file != $_GET["filename"]) {
      if($file != $page) {
        echo "<option>$file</option>\n";
      }
    }
  }
}
echo "</select>\n";

closedir($dir);

?>

ought to work..

loz
0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 

Author Comment

by:ChrisAnnable
ID: 9766748
I just relised that, the code u have doesn't actually check the url of the file its self (eg. $page = index.php), i need it to check the entire URL to that file and if it is, don't display it :)

Thankyou
0
 
LVL 13

Expert Comment

by:lozloz
ID: 9766818
that's what this part does:

$thispage = explode("/", $_SERVER["PHP_SELF"]);
$countpage = count($thispage) - 1;
$page = $thispage[$countpage];

$_SERVER["PHP_SELF"] holds the name of path information of the page e.g /admin/index.php. explode splits this string by "/" into an array, and after counting the number of elements in the array, $page stores the last element which should be the filename. the line if($file != $page) { checks that the file being put in the select box is not the same as the current page. that's the theory at least, i assume you posted because it's not working so i'll test it now and try and fix it

loz
0
 
LVL 13

Expert Comment

by:lozloz
ID: 9766919
well it seems to work with me in its present form

loz
0
 

Author Comment

by:ChrisAnnable
ID: 9769060
if i put:

http://website.com?filename=index.php

in the url, it works...

BUT, if you put http://website.com?filename=/newusers/bja/index.php

it doesn't detect it as the same file!?

How can i fix this...

Thankyou
0
 
LVL 13

Expert Comment

by:lozloz
ID: 9770672
sorry i was using the filename itself rather than the variable filename..

change:

$thispage = explode("/", $_SERVER["PHP_SELF"]);

to:

$thispage = explode("/", $_GET["filename"]);

loz
0
 

Author Comment

by:ChrisAnnable
ID: 9785389
I think you were a bit confused, but i figured it out anyway :P

if($_SERVER["HTTP_HOST"]."/".$file !=  $_SERVER["HTTP_HOST"].$_SERVER["PHP_SELF"])

Thankyou for your help, i'm accepting ur response :)

BJA
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now