karan23424 Posted May 14, 2009 Share Posted May 14, 2009 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. Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted May 15, 2009 Share Posted May 15, 2009 $_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); } Quote Link to comment Share on other sites More sharing options...
nadeemshafi9 Posted May 15, 2009 Share Posted May 15, 2009 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); } Quote Link to comment Share on other sites More sharing options...
Mark Baker Posted May 15, 2009 Share Posted May 15, 2009 >> 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). Quote Link to comment Share on other sites More sharing options...
nadeemshafi9 Posted May 17, 2009 Share Posted May 17, 2009 >> 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 Quote Link to comment Share on other sites More sharing options...
Daniel0 Posted May 17, 2009 Share Posted May 17, 2009 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. Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted May 17, 2009 Share Posted May 17, 2009 Why take out the empty function? Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted May 17, 2009 Share Posted May 17, 2009 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); } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.