Date parsed: 07/05/2008 17:57:28
Date: Wed, 07 May 2008 16:57:28 +0100
Geoff Berrow wrote:
> Message-ID: <82XXD1CpBXIIFwO1@nospam.demon.co.uk> from Dominic Sexton
> contained the following:
>
>>> But this code
>>>
>>> if( strpos($_SERVER['PHP_SELF'],"mathematica/index.php")==false )
>>> echo "<li><a href=\"http://www.g8wrb.org/mathematica/\">Mathem
>>> atica</a></li>\n";
>>>
>>> does not.
>
> Actually, that's not what you have in your code. Note the forward slash
> in front of mathematica.
>
> if( strpos($_SERVER['PHP_SELF'],"/mathematica/index.php")==false )
> echo "<li><a
> href=\"http://www.g8wrb.org/mathematica/\">Mathematica</a></li>\n";
>
> As Dominic pointed out this evaluates to a non-Boolean value which
> evaluates to FALSE, in this case, 0
>
> === should sort it out
>
> However, I find the code to be a bit long winded.
>
> Why not just do a simple comparison?
> if( $_SERVER['PHP_SELF']!="/mathematica/index.php")
> echo "<li><a
> href=\"http://www.g8wrb.org/mathematica/\">Mathematica</a></li>\n";
>
> Even better, I'd set up an array of links (which could possibly be
> dynamically generated eventually)
>
> $links=array("Mathematica"="/mathematica/index.php","Triodes"=>"/triodes/index.php","Other
> file"=>"/otherfile.php", ...add more links as required);
>
> Then:
>
> foreach($links as $key=$value){
> if( $_SERVER['PHP_SELF']!=$value)
> echo "<li><a href=\"$value\">$key</a></li>\n";
> }
> }
>
Thanks a lot for that.
I implemented something based on what you suggested. I decided to move
ALL .php files (with the exception of the menu itself and the main home
page) to subdirectories.
i.e what was previously
http://www.g8wrb.org/y799.phpis now
http://www.g8wrb.org/y799/index.phpThis means people will not have .php on the end of any links. Hence I
need to append index.php to my links before comparing with
$_SERVER['PHP_SELF']. But the following seems to be ok.
$links=array(
"Mathematica"=>"/mathematica/",
"Triodes"=>"/triodes/",
"Tetrodes"=>"/tetrodes/",
"Pentodes"=>"/pentodes/",
"Bases"=>"/bases/",
"Goodies"=>"/useful-stuff/",
"Application notes"=>"/application-notes/",
"Browse"=>"/data/",
"Thanks to"=>"/thanks/",
"Goodies"=>"/useful-stuff/",
"Solaris laptop"=>"/useful-stuff/Sun/laptop/",
"Y799"=>"/y799/",
"YC156"=>"/yc156/",
"New data"=>"/recently-added/",
"Yagi Uda"=>"/yagi/",
"Help"=>"/help/",
"Links"=>"/links/"
);
foreach($links as $key=>$value){
// compare the actual file name with the data above, after
appending index.php"
$fullfile=$value."index.php";
$f=$_SERVER['PHP_SELF'] ;
// echo "$f $fullfile<br><br>";
if( $_SERVER['PHP_SELF'] !=$fullfile)
echo "<li><a href=\"$value\">$key</a></li>\n";
}
I might look some time at creating some sub-menus. Even if my menus are
not the best in the world, I'd rather something I understand, than some
black-magic which works.