<?php
// FILE: protect_vulnerability_error_handling_if.php
// protecting against common vulnerabilities
// error handling

// initialize all variables before using!
$value = array(1,2,3,4,5);
$name  = '';
$list  = '';
$error = '';
$check = '';

// use "ternary" operator to check isset() and provide default
// don't forget to filter and validate all input!!!
$name = (isset($_GET['name'])) ? strip_tags($_GET['name']) : 'guest';

// if 1st condition fails, 2nd condition is not tested
if (isset($value[5]) && $value[5] == 0) {
	$error = 'No Value!';
}


// add additional "if" statements as needed
if (is_array($list)) {
	$check .= '<ul>';
	foreach ($list as $item) {
		$check .= '<li>Item :' . $item . '</li>';
	}
	$check .= '</ul>';
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Protect Against Vulnerabilities</title>
</head>
<body>
<h1>protect_vulnerability_error_handling_if.php</h1>

<h3>TEST</h3>

<br />Name: <?php echo htmlspecialchars($name); ?>
<br />Check: <?php echo $check; ?>

<br /><b>NOTE:</b>
<br />We allowed the fatal error to occur
<br />All fatal errors must be addressed!!!
<br />
<br />Value: <?php echo sum($value); ?>

</body>
</html>
