php - Simple basic Username and Password code for 1 user not working -
i new making websites , l still learning. have spent huge amount of time today trying figure out wrong in piece of code i'm trying use. appreciated.
main problem upon submit of incorrect or correct username/password, goes blank page , not displaying incorrect username/password message. thanks. steve
html
<form id='login' action='login.php' method='post' accept-charset='utf-8'> <fieldset> <legend>login</legend> <input type='hidden' name='submitted' id='submitted' value='1'/> <label for='username' >username: </label> <input type="text" id="username" name="username" maxlength="50" required="true" /> <label for='password' >password:</label> <input type='password' name='password' id='password' maxlength="50" required="true"/> <input type='submit' name='submit' value='submit' /> </fieldset> </form>
php
<?php session_start(); if(isset($_post['username'])){ if(($_post['username'] == "admin") && ($_post['password'] == "adminpass")) { $_session['secured'] = "secured"; } else { echo "oops! looks username , password not i'm looking for, sorry can't continue <p><a href='?'>lets try again...</a>"; } } if(!isset($_session['secured'])) { echo "<form method='post'> <form id='login' action='login.php' method='post' accept-charset='utf-8'> <fieldset> <legend>login</legend> <input type='hidden' name='submitted' id='submitted' value='1'/> <label for='username' >username: </label> <input type="text" id="username" name="username" maxlength="50" required="true" /> <label for='password' >password:</label> <input type='password' name='password' id='password' maxlength="50" required="true"/> <input type='submit' name='submit' value='submit' /> </fieldset> </form> } else { ?> <html> <head> <title>session login</title> </head> <body> <p>you have been logged in ... </p> </body> </html> <?php } ?>
there syntax/issues in php code section
name="username"
not same$_post['username']
->username
!=username
- unescaped double quotes
"
inusername
&password
inputs -><input type="text" ...
should<input type=\"text\" ...
or<input type='text' ...
- you missing closing
";
after</form>
, before} else
in php -></form> }else{
should</form>"; }else{
try updated php code to
<?php session_start(); if(isset($_post['username'])){ if(($_post['username'] == "admin") && ($_post['password'] == "adminpass")) { $_session['secured'] = "secured"; } else { echo "oops! looks username , password not i'm looking for, sorry can't continue <p><a href='?'>lets try again...</a>"; } } if(!isset($_session['secured'])) { echo "<form method='post'> <form id='login' action='login.php' method='post' accept-charset='utf-8'> <fieldset> <legend>login</legend> <input type='hidden' name='submitted' id='submitted' value='1'/> <label for='username' >username: </label> <input type='text' id='username' name='username' maxlength='50' required='true' /> <label for='password' >password:</label> <input type='password' name='password' id='password' maxlength='50' required='true'/> <input type='submit' name='submit' value='submit' /> </fieldset> </form>"; } else { ?> <html> <head> <title>session login</title> </head> <body> <p>you have been logged in ... </p> </body> </html> <?php } ?>
Comments
Post a Comment