Forum Moderators: coopster

Message Too Old, No Replies

Problems with $ SERVER['REQUEST URI']

Running PHP 5.2.6 / Apache 2.2.8

         

jdbnd

9:57 pm on Sep 27, 2008 (gmt 0)

10+ Year Member



I've got an issue with some website code (PHP inside one of my webpages) and was hoping somebody here might have an idea.

Here's the offending code:

<div id="rate-site"<?php if ( $_SERVER['REQUEST_URI']=='/' ) echo ' class="invisible"'; ?>>

This is used to make the "rate-site" page element invisible on the home page, e.g. when the browser requests "http://localhost/wheremysiteis/"

However - it just doesn't work. When I go to that URL, that's exactly what shows in the URL bar (it doesn't resolve to /index.php or anything) and I also tried replacing '/' with '/index.php' or '/index.php/' - makes no difference.

The code was originally written for PHP4, so maybe this function behaves differently in PHP5?

Help... hopefully it's something simple and dumb.

Thanks,
Joe

jdbnd

10:13 pm on Sep 27, 2008 (gmt 0)

10+ Year Member



Forgot to mention - I'm running WAMP (Windows XP Home).

Joe

venelin13

11:30 am on Sep 28, 2008 (gmt 0)

10+ Year Member



It is not related to the PHP version.

Instead of using $_SERVER['REQUEST_URI'], try to use $_SERVER['SCRIPT_NAME'] - in this case you will always be provided with the requested script name, no matter of the request URL.

In other words, no matter if the client visit your website through http://www.example.org or http://www.example.org/index.php you always now the script name, which the server executes.

Also note, if this script running in a subdirectory, as you show:

[localhost...]

The $_SERVER['SCRIPT_NAME'] value will be sort of: "/wheremysiteis/index.php"

The SCRIPT_NAME will not contain any parameters, passed to the page (e.g.: index.php?id=32 ) but the REQUEST_URI will contains them all!