Jump to content

How to avoid error log entries?


jeffg

Recommended Posts

I was looking through my Apache error log and came across lines such as the following:

[error] [client 192.168.1.2] PHP Notice:  Undefined index:  cancel in C:\\Apache\\htdocs\\login.php on line 83, referer: http://vcwb/index.html

This is the line that causes it:

if ($_POST['cancel']){	do_cancel();}elseif ($_POST['login'])....

I do this sort of thing all the time to check whether something has been clicked (or whatever). Is there a better way of writing this code so it doesn't post the warning?

Link to comment
Share on other sites

if (isset($_POST['cancel']))If you also want to check the value:if (isset($_POST['cancel']) && $_POST['cancel'] == true)
I have sooo many references to POST and SESSION variables, that rather than inflate my code by doing this everywhere, I have created a file varcheck.inc with the following:
<?php// varcheck.inc// Checks variables are set before accessfunction post($index){	$ret = false;	if (isset($_POST["$index"]))		$ret = $_POST["$index"];	return $ret;}function session($index){	$ret = false;	if (isset($_SESSION["$index"]))		$ret = $_SESSION["$index"];	return $ret;}?>

and have replaced all my references to $_POST['index'] with post('index'), and the same for $_SESSION. Maybe takes a bit more time to process, but at least it was quick to change, and avoids all those errors in Apache's error log. :)

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...