REQUEST_URI not working on PHP5

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
tcsenter
Forum Newbie
Posts: 5
Joined: Thu Jan 01, 2009 12:34 pm

REQUEST_URI not working on PHP5

Post by tcsenter »

I recently got a new server hosting a web form and one line of code doesn't work anymore. It was written about 2001.
It is used to capture the URL of the form the visitor has completed.

What would I need to change to make this work in PHP5?

Code: Select all

 
<INPUT NAME=referer TYPE=hidden VALUE="<?=$_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"];?>">
 
Thanks in advance.
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

Re: REQUEST_URI not working on PHP5

Post by Eran »

PHP 5 has short tags off by default. You need to convert:

Code: Select all

<?=
to

Code: Select all

<?php echo
Also, you are missing quotes around your attributes in the input element. This might work on most browsers but it is not recommended or valid:

Code: Select all

<input name="referer" type="hidden" value="<?php echo $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"];?>">
tcsenter
Forum Newbie
Posts: 5
Joined: Thu Jan 01, 2009 12:34 pm

Re: REQUEST_URI not working on PHP5

Post by tcsenter »

This revised code

Code: Select all

<input name="referer" type="hidden" value="<?php echo $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"];?>">
resulted in the web page displaying the last 2 characters [">] and did not return anything for REQUEST_URI

any other ideas?
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

Re: REQUEST_URI not working on PHP5

Post by Eran »

What server are you using? is it IIS by any chance?

dump the contents of the $_SERVER superglobal to see what it contains:

Code: Select all

var_dump($_SERVER);
tcsenter
Forum Newbie
Posts: 5
Joined: Thu Jan 01, 2009 12:34 pm

Re: REQUEST_URI not working on PHP5

Post by tcsenter »

server is running apache on a debian linux box

i dont have admin rights on it
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

Re: REQUEST_URI not working on PHP5

Post by Eran »

you don't need administrator privileges to run var_dump...
tcsenter
Forum Newbie
Posts: 5
Joined: Thu Jan 01, 2009 12:34 pm

Re: REQUEST_URI not working on PHP5

Post by tcsenter »

Here is what came out with my actual url replaced with mywebsite.com:

array(34) { ["DOCUMENT_ROOT"]=> string(8) "/var/www" ["HTTP_ACCEPT"]=> string(63) "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8" ["HTTP_ACCEPT_CHARSET"]=> string(30) "ISO-8859-1,utf-8;q=0.7,*;q=0.7" ["HTTP_ACCEPT_ENCODING"]=> string(12) "gzip,deflate" ["HTTP_ACCEPT_LANGUAGE"]=> string(14) "en-us,en;q=0.5" ["HTTP_CONNECTION"]=> string(10) "keep-alive" ["HTTP_COOKIE"]=> string(111) "X-Mapping-caklakng=F36074DC35B97692267EF5213570252C; name=submitted; ysm_bbk15HJ7KHALKJLSUV23VUIRAVFO3K=8216604" ["HTTP_HOST"]=> string(28) "www.mywebsite.com" ["HTTP_KEEP_ALIVE"]=> string(3) "300" ["HTTP_USER_AGENT"]=> string(90) "Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.0.5) Gecko/2008120122 Firefox/3.0.5" ["HTTP_X_CLUSTER_CLIENT_IP"]=> string(14) "24.176.247.212" ["PATH"]=> string(28) "/bin:/usr/bin:/usr/local/bin" ["REMOTE_ADDR"]=> string(13) "172.16.10.118" ["REMOTE_PORT"]=> string(5) "21842" ["SCRIPT_FILENAME"]=> string(78) "/mnt/target03/356076/363244/www.mywebsite.com/web/content/test4.php" ["SCRIPT_URI"]=> string(45) "http://www.mywebsite.com/test4.php" ["SCRIPT_URL"]=> string(10) "/test4.php" ["SERVER_ADDR"]=> string(13) "172.16.11.247" ["SERVER_ADMIN"]=> string(19) "webmaster@localhost" ["SERVER_NAME"]=> string(28) "www.mywebsite.com" ["SERVER_PORT"]=> string(2) "80" ["SERVER_SIGNATURE"]=> string(80) "
Apache/1.3.34 Server at http://www.mywebsite.com Port 80
" ["SERVER_SOFTWARE"]=> string(78) "Apache/1.3.34 (Debian) mod_gzip/1.3.26.1a AuthMySQL/4.3.9-2 PHP/5.2.0-8+etch10" ["GATEWAY_INTERFACE"]=> string(7) "CGI/1.1" ["SERVER_PROTOCOL"]=> string(8) "HTTP/1.1" ["REQUEST_METHOD"]=> string(3) "GET" ["QUERY_STRING"]=> string(0) "" ["REQUEST_URI"]=> string(10) "/test4.php" ["SCRIPT_NAME"]=> string(10) "/test4.php" ["PATH_TRANSLATED"]=> string(78) "/mnt/target03/356076/363244/www.mywebsite.com/web/content/test4.php" ["PHP_SELF"]=> string(10) "/test4.php" ["REQUEST_TIME"]=> int(1230843234) ["argv"]=> array(0) { } ["argc"]=> int(0) }
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

Re: REQUEST_URI not working on PHP5

Post by Eran »

REQUEST_URI and SERVER_NAME are both there and have values, so it's weird that it's not working. Could you post some more of the code around that line? maybe the problem is there.

(also, I didn't mention it - but you should wrap var_dump calls with <pre> tags for readability)
tcsenter
Forum Newbie
Posts: 5
Joined: Thu Jan 01, 2009 12:34 pm

Re: REQUEST_URI not working on PHP5

Post by tcsenter »

Here is the relevant code around it

Code: Select all

 
<form name="mform" action="http://mydomain.com/form/autoform.php" method="post" onsubmit="return validate()">
<input name="referer" type="hidden" value="<?php echo $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"];?>">
<input name="redirect" type="hidden" value="http://mydomain.com/thanks.php">
 
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

Re: REQUEST_URI not working on PHP5

Post by Eran »

How are you testing to see if it outputs the correct values or not?
Post Reply