Forum Moderators: coopster
<?php
$folder = "";
if(stristr($_SERVER['REQUEST_URI'], "index.php"))
$folder = "home";
if(stristr($_SERVER['REQUEST_URI'], "/approach/"))
$folder = "approach";
if(stristr($_SERVER['REQUEST_URI'], "/services/"))
$folder = "services";
if(stristr($_SERVER['REQUEST_URI'], "/projects/"))
$folder = "projects";
if(stristr($_SERVER['REQUEST_URI'], "/contact/"))
$folder = "contact";
?>
I can target all the other folders in my root, but in php how would i specify the server to target that index.php file on root level, i have tried various other methods but no joy
regards
w9914420
$folder = "";
if(stristr($_SERVER['REQUEST_URI'], "home/beta/public_html/"))
$folder = "home";
if(stristr($_SERVER['REQUEST_URI'], "/approach/"))
$folder = "approach";
if(stristr($_SERVER['REQUEST_URI'], "/services/"))
$folder = "services";
if(stristr($_SERVER['REQUEST_URI'], "/projects/"))
$folder = "projects";
if(stristr($_SERVER['REQUEST_URI'], "/contact/"))
$folder = "contact";
?>
<div id="navigation">
<ul class="navigation">
<li class="home<?php if($folder == "home") echo "page"; ?> tab"><a title="What we do and who we are." href="http://www.mysite.com" >Home</a></li>
<li class="approach<? if($folder == "approach") echo "page";?> tab"><a title="Our methodology and thoughts." href="http://www.mysite.com/approach/" >Approach</a></li>
<li class="services<? if($folder == "services") echo "page";?> tab"><a title="What we have to offer you." href="http://www.mysite.com/services/" >Services</a></li>
<li class="projects<? if($folder == "projects") echo "page";?> tab"><a title="A collection of our works." href="http://www.mysite.com/projects/" >Projects</a></li>
<li class="contact<? if($folder == "contact") echo "page";?> tab"><a title="Come and work with us." href="http://www.mysite.com/contact/" >Contact</a></li>
</ul>
Ideally the way in which the script works is to change the selected to page which creates the link to be coloured. unfortunately this those not work is there anything else I could maybe check
regards
w9914420
if(stristr($_SERVER['REQUEST_URI'], "home/beta/public_html/"))
$folder = "home";
This is never going to evaluate to true since "home/beta/public_html/" (the server-side path) is never going to be part of the REQUEST_URI (client-side URL as seen in the browser).
I simply want to target the index.php on my server which is located in the root...
To target just the file, you could do:
if ($_SERVER['PHP_SELF'] == '/index.php')
$folder = 'home';
To check if you are in any file in the web root, you could check for any more '/' after the first one in PHP_SELF, if there are then you are in a sub folder, if not then you are in the web root.
if (strpos($_SERVER['PHP_SELF'],'/',1) === false)
$folder = 'home';