homepage Welcome to WebmasterWorld Guest from 54.237.54.83
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Calling a file in php
trying to locate the index.php file on my server
w9914420




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

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

 

lethal0r




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

use the absolute location?

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

penders




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

To find out the absolute location:

$_SERVER['DOCUMENT_ROOT'].'/index.php'

w9914420




msg:3942026
 6:32 pm on Jun 28, 2009 (gmt 0)

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

penders




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

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';

w9914420




msg:3942916
 5:16 am on Jun 30, 2009 (gmt 0)

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

regards

w9914420

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved