Welcome to WebmasterWorld Guest from 54.162.240.235

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Calling a file in php

trying to locate the index.php file on my server

     
8:54 am on Jun 28, 2009 (gmt 0)

10+ Year Member



I simply want to target the index.php on my server which is located in the root I have created the following php script

<?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

12:01 pm on Jun 28, 2009 (gmt 0)

5+ Year Member



use the absolute location?

/home/user/website/public_html or w/e it is for you

12:34 pm on Jun 28, 2009 (gmt 0)

WebmasterWorld Senior Member penders is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month



To find out the absolute location:

$_SERVER['DOCUMENT_ROOT'].'/index.php'
6:32 pm on Jun 28, 2009 (gmt 0)

10+ Year Member



thank you guys, I have managed to work out the absolute path of the file. the entire code looks like this:

$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

11:10 am on Jun 29, 2009 (gmt 0)

WebmasterWorld Senior Member penders is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month



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';
5:16 am on Jun 30, 2009 (gmt 0)

10+ Year Member



Thank you penders,
I know understand where i was going wrong in my coding.

regards

w9914420

 

Featured Threads

Hot Threads This Week

Hot Threads This Month