[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

PHP Notice: Undefined index: REQUEST_URI

Posted on 2011-05-04
10
Medium Priority
?
3,721 Views
Last Modified: 2013-12-13
$_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
Comment
Question by:rgb192
10 Comments
 
LVL 84

Expert Comment

by:Dave Baldwin
ID: 35695379
What server are you on?  And what version of PHP?
0
 
LVL 84

Expert Comment

by:Dave Baldwin
ID: 35695387
$_SERVER['REQUEST_URI'] is available on Apache and IIS.
0
 

Author Comment

by:rgb192
ID: 35695404
using iis7 php 5.3.6 now

not sure of my old server
I think it was php 5.2 iis7
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 84

Expert Comment

by:Dave Baldwin
ID: 35695901
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
 
LVL 27

Expert Comment

by:Lukasz Chmielewski
ID: 35695999
Read this
http://www.orangehrm.com/forum/viewtopic.php?t=20#38

This seems to be the IIS only
0
 
LVL 84

Expert Comment

by:Dave Baldwin
ID: 35696083
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
 
LVL 12

Accepted Solution

by:
Mohamed Abowarda earned 2000 total points
ID: 35696302
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
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 35698407
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
 

Author Closing Comment

by:rgb192
ID: 35741931
suggestion works on both versions of php that I have used

now I can use $_SERVER['REQUEST_URI']
 on php5.2.17
0
 
LVL 84

Expert Comment

by:Dave Baldwin
ID: 35741995
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

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to dynamically set the form action using jQuery.
Suggested Courses
Course of the Month18 days, 9 hours left to enroll

825 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question