php - i am trying to practice a simple session code in my house in xamp -
but how page not showing error message. not redirecting page want redirect after successful login. want login page redirected @ home page , show message , when logout link clicked page again come login page
<?php session_start(); error_reporting(e_all ^ e_notice); ?> <?php if($_request["logout"]=='yes'){ unset($_session["login"]); } ?> <html> <body> <form action="" method="post"> <label>username</label><input type="text" name="unametxt" value="<?php echo $_post["unametxt"]; ?>" /> <label>password</label><input type="password" value="<?php echo $_post["password"]; ?>" /> <input type="submit" name="sbt" value="login"> </form> <?php if(isset($_post["sbt"])) { if($_post["unametxt"]== "debarun" && $_post["password"]=="1234") { $_session["login"]="yes"; $_session["uname"]=$_post["unametxt"]; $_session["passwd"]=$_post["password"]; header('location:home.php'); } else { echo "please enter correct credentials"; } } ?> </body> </html> , home page script: <?php session_start(); if(!isset($_session["login"])){ session_destroy(); header('location:login.php'); } else{ echo "welcome".$_session["uname"]."<br/>"."your password is".$_session["passwd"]; } ?> <html> <body> <form action="" method="post"> <a href="login.php?logout=yes">logout</a> </form> </body> </html> please
tell me why not working??
first thing $_post
must letter case $_post
forgot specify name="password"
password input field take look
<?php session_start(); error_reporting(e_all ^ e_notice); ?> <?php if($_request["logout"]=='yes'){ unset($_session["login"]); } ?> <html> <body> <form action="" method="post"> <label>username</label><input type="text" name="unametxt" value="<?php echo $_post["unametxt"]; ?>" /> <label>password</label><input type="password" name="password" value="<?php echo $_post["password"]; ?>" /> <input type="submit" name="sbt" value="login"> </form> <?php if(isset($_post["sbt"])) { echo $_post["password"]; if($_post["unametxt"] == "debarun" , $_post["password"] == "1234") { $_session["login"]="yes"; $_session["uname"]=$_post["unametxt"]; $_session["passwd"]=$_post["password"]; header('location:home.php'); } else { echo "please enter correct credentials"; } } ?> </body> </html>
Comments
Post a Comment