469,289 Members | 2,127 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,289 developers. It's quick & easy.

Undefined index: REQUEST_METHOD

Hi there,
I have installed a search engine on one of my websites - it had a few
bugs in it, I got all but one out of the script.

The results page works, but it displays this error on the top of the page:

Notice: Undefined index: REQUEST_METHOD in \www\search\libs\utils.php on
line 409

I have enclosed the code it refers to below. I am an amateur when it comes
to PHP, and would appreciate any help. Thanks

Line 409 is this first line.

$retVal = $GLOBALS[$envVar];
if (strlen($retVal) < 1) {
$retVal = getenv($envVar);
if (strlen($retVal) < 1) {
$retVal = $HTTP_ENV_VARS[$envVar];
if (strlen($retVal) < 1) {
$retVal = $HTTP_SERVER_VARS[$envVar];
}
}

Bandit
Jul 17 '05 #1
6 11321
Use @ to suppress the notice.

$retVal = @$GLOBALS[$envVar];

Or lower your error_reporting level.

Uzytkownik "Bandit" <In**@Bar-Guide.ca> napisal w wiadomosci
news:ra**********************@nnrp1.uunet.ca...
Hi there,
I have installed a search engine on one of my websites - it had a few
bugs in it, I got all but one out of the script.

The results page works, but it displays this error on the top of the page:

Notice: Undefined index: REQUEST_METHOD in \www\search\libs\utils.php on
line 409

I have enclosed the code it refers to below. I am an amateur when it comes to PHP, and would appreciate any help. Thanks

Line 409 is this first line.

$retVal = $GLOBALS[$envVar];
if (strlen($retVal) < 1) {
$retVal = getenv($envVar);
if (strlen($retVal) < 1) {
$retVal = $HTTP_ENV_VARS[$envVar];
if (strlen($retVal) < 1) {
$retVal = $HTTP_SERVER_VARS[$envVar];
}
}

Bandit

Jul 17 '05 #2
Chung Leong <ch***********@hotmail.com> wrote:
Use @ to suppress the notice.

$retVal = @$GLOBALS[$envVar];

Or lower your error_reporting level.


Noooooooooooooo. The correct answer is to write better code.
$retVal = $GLOBALS[$envVar];
if (strlen($retVal) < 1) {
$retVal = getenv($envVar);
if (strlen($retVal) < 1) {
$retVal = $HTTP_ENV_VARS[$envVar];
if (strlen($retVal) < 1) {
$retVal = $HTTP_SERVER_VARS[$envVar];
}
}


There are no checks if the index does exist in the array... The
nonexisting key is accessed directly...

if(array_key_exists($envVar,$GLOBALS))
{
$retVal=$GLOBALS[$envVar];
}
elseif(array_key_exists($envVar,$_ENV))
{
...
}
else
{
...
}

--

Daniel Tryba

Jul 17 '05 #3
On 2004-01-08, Daniel Tryba <ne****************@canopus.nl> wrote:
There are no checks if the index does exist in the array... The
nonexisting key is accessed directly...

if(array_key_exists($envVar,$GLOBALS))
{
$retVal=$GLOBALS[$envVar];
}


As i've found array_key_exists the most elegant way, isset is faster.
--
http://home.mysth.be/~timvw
Jul 17 '05 #4
On 2004-01-08, Bandit <In**@Bar-Guide.ca> wrote:

This is the 3th group i see your post.

Really time to lookup a usenette introduction that tells you about
multiposting and crossposting.

--
http://home.mysth.be/~timvw
Jul 17 '05 #5
Tim Van Wassenhove <eu**@pi.be> wrote:
There are no checks if the index does exist in the array... The
nonexisting key is accessed directly...

if(array_key_exists($envVar,$GLOBALS))
{
$retVal=$GLOBALS[$envVar];
}


As i've found array_key_exists the most elegant way, isset is faster.


But array_key_exists has added value: it will barf when the haystack isn't
an array. IMHO that's more important than a few us.

--

Daniel Tryba

Jul 17 '05 #6
Doing more when less will suffice is vain.

Uzytkownik "Daniel Tryba" <ne****************@canopus.nl> napisal w
wiadomosci news:bt**********@news.tue.nl...
Chung Leong <ch***********@hotmail.com> wrote:
Use @ to suppress the notice.

$retVal = @$GLOBALS[$envVar];

Or lower your error_reporting level.


Noooooooooooooo. The correct answer is to write better code.
$retVal = $GLOBALS[$envVar];
if (strlen($retVal) < 1) {
$retVal = getenv($envVar);
if (strlen($retVal) < 1) {
$retVal = $HTTP_ENV_VARS[$envVar];
if (strlen($retVal) < 1) {
$retVal = $HTTP_SERVER_VARS[$envVar];
}
}


There are no checks if the index does exist in the array... The
nonexisting key is accessed directly...

if(array_key_exists($envVar,$GLOBALS))
{
$retVal=$GLOBALS[$envVar];
}
elseif(array_key_exists($envVar,$_ENV))
{
...
}
else
{
...
}

--

Daniel Tryba

Jul 17 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by John Oliver | last post: by
26 posts views Thread by Craig Morrison | last post: by
9 posts views Thread by Alan Schroeder | last post: by
7 posts views Thread by deepak | last post: by
3 posts views Thread by number1yan | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.