Php server globals REQUEST_URI or HTTP_SERVER_VARS


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Php server globals REQUEST_URI or HTTP_SERVER_VARS
# 1  
Old 06-30-2013
Php server globals REQUEST_URI or HTTP_SERVER_VARS

Hi all,

recently I found that
PHP Code:
$_SERVER['REQUEST_URI'
does not deliver the complete url with query anymore on my server.

Code:
 http://www.example.org/search.php?stichwort=wiki
echo $_SERVER['REQUEST_URI'];
/search.php

However
PHP Code:
$GLOBALS['HTTP_SERVER_VARS']['REQUEST_URI'
works in this case.

Code:
 http://www.example.org/search.php?stichwort=wiki
echo $GLOBALS['HTTP_SERVER_VARS']['REQUEST_URI'];
/search.php?stichwort=wiki

On an other server, it was the other way round:
PHP Code:
$GLOBALS['HTTP_SERVER_VARS']['REQUEST_URI'
not working and
PHP Code:
$_SERVER['REQUEST_URI'
works well...

When googlig a solution for a code to match any case of the described above, I found this little code, which seems to work, but which I do not understand what it is doing:

Maybe some pro can tell if this code should work safely and what exactly it is doing. The syntax is new to me Smilie

PHP Code:
(isset($GLOBALS['HTTP_SERVER_VARS']) && isset($GLOBALS['HTTP_SERVER_VARS']['REQUEST_URI']))?$GLOBALS['HTTP_SERVER_VARS']['REQUEST_URI']:$_SERVER['REQUEST_URI'

Last edited by lowmaster; 06-30-2013 at 04:20 PM..
# 2  
Old 06-30-2013
Think of it as an if-then-else:
Code:
if (isset($GLOBALS['HTTP_SERVER_VARS']) && isset($GLOBALS['HTTP_SERVER_VARS']['REQUEST_URI']))
  $something = $GLOBALS['HTTP_SERVER_VARS']['REQUEST_URI'];
else
  $something = $_SERVER['REQUEST_URI'];

There are examples here: Control Structures: If - PHP Manual
This User Gave Thanks to Scott For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

7 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Test Server - Forum Code Changes for PHP 5.3.10 to PHP 7

Here is some docs of my ongoing work to port this forum PHP code which is running on 5.3.10, to PHP 7. Motivation: Unfortunately, every thing that has a beginning must have an end. PHP 5.6 active support ended January 19, 2017. It will receive security support until December 31, 2018. #1 ... (7 Replies)
Discussion started by: Neo
7 Replies

2. UNIX for Advanced & Expert Users

how to know which version of PHP and apache is in my server?

Hi, How to get the version of php, apache and WebSphere instealled in my server. The OS is AIX. Thanks in advance. R R VARMA (1 Reply)
Discussion started by: RRVARMA
1 Replies

3. Web Development

php and perl on apache server

I'm having problems opening php and perl files on Apache. The server hasn't any association with those type of files by default and a window asking to choose a program to open them popups from the browser. How can I do to process them with the browser Thanks in advance. (1 Reply)
Discussion started by: capibolso
1 Replies

4. Shell Programming and Scripting

how to access globals in a function

I know any globals can be directly modified in a function without passing/returning parameters- provided the function is written within the same file. However, when I wrote functions in a saparate file (so hopefully they can be re-used by multiple script programs), and then call them from the main,... (11 Replies)
Discussion started by: bluemoon1
11 Replies

5. Shell Programming and Scripting

Hiding PHP code on the server

Hi all, Sometime back, had put up a Q regarding hiding perl code. A: There is a utility known as 'pp' which comes along with PAR. Downloaded from CPAN. These people have done wonderful work I must say. Cool executables from perl scripts. Have one more... (4 Replies)
Discussion started by: sudhir_onweb
4 Replies

6. UNIX for Advanced & Expert Users

AIX, web server, php

Hi there, I'm sorry , I can't be here every day but everytime I have a problem, I remember of you :) So, here goes the situation. I'm working with an installed AIX 5.2. I didn't make that install. I had to install php by a package that I've found in... (0 Replies)
Discussion started by: kisoun
0 Replies

7. Shell Programming and Scripting

perl: globals and a package.

I am still learning perl and confused on this script I am revising at work. The original author uses a package, which I have left in the code; however, I cannot seem to access the global variable $dir. Code snippet: I have also tried using $RRD_MG::dir to no avail. Thank you. (6 Replies)
Discussion started by: effigy
6 Replies
Login or Register to Ask a Question