• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 4651
  • Last Modified:

PHP Notice: Undefined index: REQUEST_URI

$_SERVER['REQUEST_URI']
was working on another version of php that I had

but now I get notices and there is no way to eliminate these notices
error_reporting(0);
ini_set('display_errors', FALSE);
PHP Notice: Undefined index: REQUEST_URI
0
rgb192
Asked:
rgb192
1 Solution
 
Dave BaldwinFixer of ProblemsCommented:
What server are you on?  And what version of PHP?
0
 
Dave BaldwinFixer of ProblemsCommented:
$_SERVER['REQUEST_URI'] is available on Apache and IIS.
0
 
rgb192Author Commented:
using iis7 php 5.3.6 now

not sure of my old server
I think it was php 5.2 iis7
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
Dave BaldwinFixer of ProblemsCommented:
Here are two pages/programs that will display all of the SERVER variables available on your server.  One is in Classic ASP and the other is in PHP.  I added a third in a simple version of ASP.NET in case the Classic ASP doesn't run.  The three programs will show slightly different results but they will show you what is available for those languages.
<%@ LANGUAGE = VBScript %>
<%  Option Explicit		%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>
<head>
<title>ASP Server Variables</title>
</head>
<body>
<h1>ASP Server Variables</h1>
<%
Dim item

For each item in Request.ServerVariables
	Response.Write "<b>" & item & "</b>: " _
	& Request.ServerVariables(item) _
	& "<br>" & vbCrLf
Next
%>

</body>
</html>

Open in new window

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
<title>PHP Server Variables</title>
</head>
<body>
<h1>PHP Server Variables</h1>
<?php

//reset($_SERVER);
foreach($_SERVER as $key => $value) {
    echo "<b>$key :</b> $value<br />\n";
}
?>
</body>
</html>

Open in new window

<%@ Page Language = "VBScript" AspCompat="True" %>
<% Response.Buffer = true %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
 "http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
<title>ASPX .NET Server Variables</title>
</head>
<body>
<h1 align="center">ASPX .NET Server Variables</h1>
<%
Dim loop1, loop2 As Integer
Dim arr1(), arr2() As String
Dim coll As NameValueCollection

' Load ServerVariable collection into NameValueCollection object.
coll=Request.ServerVariables 
' Get names of all keys into a string array.
arr1 = coll.AllKeys 
For loop1 = 0 To arr1.GetUpperBound(0)
   Response.Write("Key: " & arr1(loop1) & "<br>")
   arr2 = coll.GetValues(loop1) ' Get all values under this key.
   For loop2 = 0 To arr2.GetUpperBound(0)
      Response.Write("Value " & CStr(loop2) & ": " & Server.HtmlEncode(arr2(loop2)) & "<br>")
   Next loop2
Next loop1

Response.Write ("<br>" & vbCrLf)
Response.Write ("HTTP_REFERER" & ": " _
	& Request.ServerVariables("HTTP_REFERER") _
	& "<br>" & vbCrLf)

%>

</body>
</html>

Open in new window

0
 
Lukasz ChmielewskiCommented:
Read this
http://www.orangehrm.com/forum/viewtopic.php?t=20#38

This seems to be the IIS only
0
 
Dave BaldwinFixer of ProblemsCommented:
I see all the complaints in Google but I get $_SERVER['REQUEST_URI'] with PHP 5.2.17 on both IIS5.1 and IIS7.
0
 
Mohamed AbowardaSoftware EngineerCommented:
Since you are using IIS, add the following code in some initialization section:
$HTTP_SERVER_VARS['REQUEST_URI'] = ( isset($HTTP_SERVER_VARS['REQUEST_URI']) ? $HTTP_SERVER_VARS['REQUEST_URI'] : $HTTP_SERVER_VARS['SCRIPT_NAME'] . (( isset($HTTP_SERVER_VARS['QUERY_STRING']) ? '?' . $HTTP_SERVER_VARS['QUERY_STRING'] : '')));

Open in new window


Now you can use the following to get REQUEST_URI:
$HTTP_SERVER_VARS['REQUEST_URI'];

Open in new window

0
 
Ray PaseurCommented:
Please install this script on your server and post a link to it here so we can see how things are configured.  This will be faster than guessing about your setup.  You can take the script down later.  Thanks, ~Ray
<?php phpinfo();

Open in new window

0
 
rgb192Author Commented:
suggestion works on both versions of php that I have used

now I can use $_SERVER['REQUEST_URI']
 on php5.2.17
0
 
Dave BaldwinFixer of ProblemsCommented:
Note that it isn't PHP but the server that reports that info to PHP.   Different servers report different variables and some can be turned off by the people running the server.  You can use the programs I posted above to see what your server reports.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now