Notice: Undefined variable: errorUser in /opt/lampp/htdocs/www/Borgen44/default_admin.php on line 37
<?php require("inc/config.php"); require("mysql.open.php"); require("functions.php"); if ($_SERVER["QUERY_STRING"] == "admin") { include("default_admin.php"); }elseif($_SERVER["QUERY_STRING"] == "phpinfo") { include("phpinfo.php"); }elseif(isset($_GET["agent"]) && $_GET["agent"] == "handheld") { include("default_handheld.php"); }else{ include("default_site.php"); } require("inc/mysql.close.php"); exit; ?>
<?php if (isset($_POST["submit"]) && inputCheck($_POST["username"], "username") == TRUE) { echo "brugernavn: ok"; } if (isset($_POST["submit"]) && inputCheck($_POST["password"], "password") == TRUE) { echo "password: ok"; } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title></title> <meta name="description" content="[]" /> <meta name="keywords" content="[]" /> <meta name="author" content="[]" /> <meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1" /> </head> <body> <table width="20%" border="1" align="center"> <form action="" method="post" name="login"> <input type="hidden" name="submit" value="login_form"> <tr> <td colspan="2"><h2>Admin Log Ind</h2></td> </tr> <tr> <td width="20%">Brugernavn:</td> <td><input type="text" size="35" name="username" id="username" /><?php echo $errorUser; ?></td> </tr> <tr> <td width="20%">Password:</td> <td><input type="password" size="35" name="password" id="password" /><?php echo $errorPass; ?></td> </tr> <tr> <td colspan="2"><input type="submit" value="Log Ind" name="login" id="login" /></td> </tr> </form> </table> </body> </html>
function inputCheck($string, $type) { $valid = TRUE; switch ($type) { case "username": if (empty($string)) { $valid = FALSE; $errorUser = "Du har ikke skrevet et brugernavn."; } elseif (preg_match("/^[0-9a-zA-Z_]{8,25}$/", $string) == FALSE) { $valid = FALSE; $errorUser = "Brugernavnet skal være imellem 8 og 25 bogstaver eller tal."; } break; case "password": if (empty($string)) { $valid = FALSE; $errorPass = "Du har ikke skrevet et password."; } elseif (preg_match("/^[0-9a-zA-Z_]{12,25}$/", $string) == FALSE) { $valid = FALSE; $errorPass = "Passwordet skal være imellem 12 og 25 bogstaver eller tal."; } break; case "email": if (filter_var($string, FILTER_VALIDATE_EMAIL)) { $valid = FALSE; $errorEmail = "Dette er ikke en korrekt e-mail adresse"; } break; case "": break; default: } return $valid; }
function inputCheck($string, $type) { $valid = TRUE; switch ($type) { case "username": if (empty($string)) { $errorUser = "Du har ikke skrevet et brugernavn."; if (preg_match("/^[0-9a-zA-Z_]{8,25}$/", $string) == FALSE) { $errorUser = "Brugernavnet skal være imellem 8 og 25 bogstaver eller tal."; } else { $errorUser = ""; } } else { $errorUser = ""; } return $errorUser; break; case "password": if (empty($string)) { $errorPass = "Du har ikke skrevet et password."; if (preg_match("/^[0-9a-zA-Z_]{12,25}$/", $string) == FALSE) { $errorPass = "Passwordet skal være imellem 12 og 25 bogstaver eller tal."; } else { $errorPass = ""; } } else { $errorPass = ""; } return $errorPass; break; case "email": if (filter_var($string, FILTER_VALIDATE_EMAIL)) { $errorEmail = "Dette er ikke en korrekt e-mail adresse"; } else { $errorEmail = ""; } return $errorEmail; break; case "": break; default: } }
<?php $errorUser = inputCheck($_POST["username"], "username"); echo $errorUser; ?>
Notice: Undefined index: username in /opt/lampp/htdocs/www/Borgen44/default_admin.php on line 37 Brugernavnet skal være imellem 8 og 25 bogstaver eller tal.