Reputation: 111
i been working in the login code .. it works fine except this message that appears when openenig the login page !!
Notice: Undefined index: msg in C:\xampp\htdocs\thesite\login.php on line 103
it has appeard when i typed this in loginExcution.php
else {
//Login failed
header("location:login.php? msg=*invalid name or password");
exit();
}
and this to show the message in the login form page
<?php
$msg = $_GET['msg'];
print $msg;
?>
Upvotes: 0
Views: 102
Reputation: 1668
Don't put spaces in your header("Location:
.
else {
//Login failed
header("Location: login.php?msg=invalid%20name%20or%20password");
exit();
}
EDIT: The %20
s are actually spaces. Look at the PHP function urlencode()
if you want more info. The code above is equivalent to this:
else {
//Login failed
header("Location: login.php?msg=" . urlencode("invalid name or password"));
exit();
}
Upvotes: 2
Reputation: 2294
beside removing first space mentioned in simplyianm answer. if the code reaches this line $_GET['msg'] and msg is not defined index, it will trigger the notice. you can do this instead
if (isset($_GET['msg'])){
$msg=$_GET['msg'];
print $msg;
}
though, passing the message content through the url is not a good idea. users can pass some javascript and send the link to unsuspecting user. Instead you could make it a code login.php?msg=invalid
then in the code
if (isset($_GET['msg'])){
switch ($msg){
case "invalid":
echo "Invalid username or password";
break;
}
}
Upvotes: 0