Jump to content

getting strange erros from error logs


karan23424

Recommended Posts

i am getting this error in error logs.

 

[Thu May 14 09:01:03 2009] [error] [client 76.69.39.186] PHP Notice:  Undefined index:  o in /var/www/vhosts/facepuck.com/httpdocs/supercali/includes/start.php on line 156, referer: http://www.facepuck.com/members/groupListAll.php

 

and line no 156 on start.php is

if ((is_numeric($_REQUEST["o"]))&& ($_REQUEST["o"]!= 0)) {

  $_SESSION["o"] = $_REQUEST["o"];

  $o = $_REQUEST["o"];

} elseif ($_SESSION["o"]) {

  $o = $_SESSION["o"];

} elseif ($default_module) {

  $o = $default_module;

} else {

  $o = mysql_result(mysql_query("SELECT module_id from ".$table_prefix."modules where active = 1 order by sequence limit 1"),0,0);

}

 

 

please let me know where is the problem

its just a warning

although function is working properly

 

Thanks in advance.

Link to comment
Share on other sites

$_REQUEST['o'] may not be defined.

 

Give this a go.

if (!empty($_POST['o']) && is_numeric($_POST['o'])) {
   $_SESSION["o"] = $_REQUEST["o"];
   $o = $_REQUEST["o"];
} elseif ($_SESSION["o"]) {
   $o = $_SESSION["o"];
} elseif ($default_module) {
   $o = $default_module;
} else {
   $o = mysql_result(mysql_query("SELECT module_id from ".$table_prefix."modules where active = 1 order by sequence limit 1"),0,0);
}

Link to comment
Share on other sites

OR

if ((@is_numeric(@$_REQUEST["o"]))&& (@$_REQUEST["o"]!= 0)) {
   @$_SESSION["o"] = @$_REQUEST["o"];
   $o = @$_REQUEST["o"];
} elseif (@$_SESSION["o"]) {
   $o = @$_SESSION["o"];
} elseif ($default_module) {
   $o = $default_module;
} else {
   $o = mysql_result(mysql_query("SELECT module_id from ".$table_prefix."modules where active = 1 order by sequence limit 1"),0,0);
}

Link to comment
Share on other sites

>> nadeemshafi9

 

It isn't really good practise simply to use @ to hide errors. Better (wherever possible) to prevent the error occurring in the first place by validating inputs (in this case).

 

most definatly, but i just discovered teh @ thingy and its quite handy

Link to comment
Share on other sites

No, it's not handy. It's stupid, and in my opinion it should be removed from PHP.

 

First of all it has an impact on the performance. The way it works is that it turns off error reporting and then turns it on. You've done that eight times in that small snippet. Secondly, suppressing errors gives you problems when something goes wrong. The errors tell you what is wrong, but if you tell PHP not to report any errors then how are you going to debug it?

 

There are many bad ideas that have been implemented in PHP. Magic quotes, register globals, error suppression (@-operator), safe mode, just to name a few.

 

You don't even understand it even though you're using it. Take a look at this for instance:

 

@$_SESSION["o"] = @$_REQUEST["o"];

 

That could never result in any errors. The first one is simply an assignment, that won't result in an error unless $_SESSION is undefined or is not an array, but assuming you called session_start() earlier, it will always be that. The second one could never result in an error either because you've just checked that $_REQUEST['o'] exists, so if it didn't exist then you would never have gotten there in the first place.

Link to comment
Share on other sites

Before using any user defined variables POST, GET, COOKIE, REQUEST etc you should check that it exists first, using isset.

 

This will fix the notice

if (isset($_REQUEST["o"]) && is_numeric($_REQUEST["o"]) && $_REQUEST["o"]!= 0) {
   $_SESSION["o"] = $_REQUEST["o"];
   $o = $_REQUEST["o"];
} elseif (isset($_SESSION["o"])) {
   $o = $_SESSION["o"];
} elseif ($default_module) {
   $o = $default_module;
} else {
   $o = mysql_result(mysql_query("SELECT module_id from ".$table_prefix."modules where active = 1 order by sequence limit 1"),0,0);
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.