473,223 Members | 1,769 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,223 software developers and data experts.

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 12468
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Joe | last post by:
Back in March I submitted a patch for cgi.py to sourceforge to fix a problem with the handling of an invalid REQUEST_METHOD. I thought I followed all the steps to properly submit the bug and...
4
by: John Oliver | last post by:
PHP Notice: Undefined index: name in /home/www/reformcagunlaws.com/new.php on line 6 PHP Notice: Undefined index: address in /home/www/reformcagunlaws.com/new.php on line 7 PHP Notice: ...
26
by: Craig Morrison | last post by:
I'm getting this: PHP Notice: Undefined index: D1 in /var/www/html..... From this line of code: $id_option = $_POST; Which is posted by this:
9
by: Alan Schroeder | last post by:
The following code produces the expected results on a PC using gcc, but I need to port it (or least something similar) to a different platform/compiler. I don't think I've introduced any undefined...
7
by: deepak | last post by:
Using 'char' as an array index is an undefined behavior?
3
cassbiz
by: cassbiz | last post by:
Here are the errors that are coming up in my error_log Notice: Undefined index: andatum in /zipcode.php on line 11 Notice: Undefined index: andatum in /zipcode.php on line 12 Notice: Undefined...
3
by: number1yan | last post by:
Can anyone help me, i am creating a website and am using a php script that recomends the website to other people. I keep getting the same error and can not work out why. The error is: Notice:...
15
by: bill | last post by:
I am trying to write clean code but keep having trouble deciding when to quote an array index and when not to. sometimes when I quote an array index inside of double quotes I get an error about...
5
by: siyaverma | last post by:
Hi, I am new to php, i was doing some small chnages in a project developed by my collegue who left the job and i got the responsibility for that, After doing some changes when i run it on my...
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
0
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.