Welcome to WebmasterWorld Guest from 54.226.246.160

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

PHP script problem after changing server type

$_SERVER["REQUEST_URI"] related

     

Reflection

9:24 pm on Dec 2, 2006 (gmt 0)

10+ Year Member



I recently switched hosting from apache running on windows to unix.

Here is my problem...

On each page I include a script that controls the navigation elements of each page. Ex: inlcude("nav.php")

Within nav.php, I check the path of the page that included nav.php and write the appropriate submenu accordingly. For example, when nav.php is included from: www.mysite.com/bluewidgets/index.php it would find that it was included from a page in the "bluewidgets" section and write the appropriate submenu for bluewidgets.

I was accomplishing this by using $_SERVER["REQUEST_URI"] (within nav.php) to retrieve the path of the page that included nav.php. Since switching hosts $_SERVER["REQUEST_URI"] now returns the path of nav.php(includes/nav.php) and not the page that included nav.php. Does that make sense?

Here is the code I was using within nav.php...

$strArr = explode("/", $_SERVER["REQUEST_URI"]);
$directory = $strArr[sizeof($strArr) - 2];

switch ($directory) {
write appropriate menu...
}

Can anyone offer me some advice?

Thanks

justageek

12:28 am on Dec 3, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You could try $_SERVER['PHP_SELF'].

JAG

Reflection

1:34 am on Dec 3, 2006 (gmt 0)

10+ Year Member



Thanks JAG, but PHP_SELF gives me the same result.

coopster

2:03 am on Dec 3, 2006 (gmt 0)

WebmasterWorld Administrator coopster is a WebmasterWorld Top Contributor of All Time 10+ Year Member



What version of PHP is running on the new server?

pixeltierra

7:13 am on Dec 5, 2006 (gmt 0)

5+ Year Member



I've never had this type of need in my nav systems for a directory. I think you should reconsider your site architecture. Or if that isn't feasible, why not use non-relative links in your nav?

jatar_k

5:56 pm on Dec 5, 2006 (gmt 0)

WebmasterWorld Administrator jatar_k is a WebmasterWorld Top Contributor of All Time 10+ Year Member



try dumping all the vars in $_SERVER and see what there is

echo '<pre>';
print_r($_SERVER);
echo '</pre>';

As long as you are requesting the including file REQUEST_URI should be from that page as opposed to the actual nav file

 

Featured Threads

Hot Threads This Week

Hot Threads This Month