php - Can't get login page to redirect when user credentials are entered -


hi there i'm having problem little project i've been working on. i'm 17 years old in high school , trying learn as can html, php, mysql, etc. created database mysql , know have setup correctly, because login page i'm using able know right, , wrong user accounts. cant seem able page redirect welcome page on successful login. here code.

login page code

<?php include("config.php"); session_start();  if($_server["request_method"] == "post") {   // username , password sent form     $myusername = mysqli_real_escape_string($db,$_post['username']);   $mypassword = mysqli_real_escape_string($db,$_post['password']);     $sql = "select id admin username = '$myusername' , passcode = '$mypassword'";   $result = mysqli_query($db,$sql);   $row = mysqli_fetch_array($result,mysqli_assoc);   $active = $row['active'];    $count = mysqli_num_rows($result);    // if result matched $myusername , $mypassword, table row must 1 row    if($count == 1) {      session_register("myusername");      $_session['username'] = $myusername;       header("location: welcome.php");   }else {      $error = "your login name or password invalid";   } } ?>   <html>    <head>   <title>login page</title>    <style type = "text/css">      body {         font-family:arial, helvetica, sans-serif;         font-size:14px;      }       label {         font-weight:bold;         width:100px;         font-size:14px;      }       .box {         border:#666666 solid 1px;      }      </style>       </head>       <body bgcolor = "#ffffff">       <div align = "center">      <div style = "width:300px; border: solid 1px #333333; " align = "left">         <div style = "background-color:#333333; color:#ffffff; padding:3px;"><b>login</b></div>          <div style = "margin:30px">             <form action = "" method = "post">               <label>username  :</label><input type = "text" name =     "username" class = "box"/><br /><br />               <label>password  :</label><input type = "password" name = "password" class = "box" /><br/><br />               <input type = "submit" value = " submit "/><br />            </form>             <div style = "font-size:11px; color:#cc0000; margin-top:10px"><?php echo $error; ?></div>          </div>       </div>    </div>  </body> </html> 

session code

<?php include('config.php'); session_start();  $user_check = $_session['myusername'];  $ses_sql = mysqli_query($db,"select username admin username = '$user_check' ");  $row = mysqli_fetch_array($ses_sql,mysqli_assoc);  $login_session = $row['username'];  if(!isset($_session['username'])){   header("location:welcome.php"); } ?> 

redirected page

<?php include('session.php'); ?> <html>   <head>   <title>welcome </title>  </head>   <body>   <h1>welcome <?php echo $login_session; ?></h1>    <h2><a href = "logout.php">sign out</a></h2>  </body>  </html> <?php session_start();  if(session_destroy()) {   header("location: login.php"); } strong text ?> 

 <?php  session_start();  include("config.php");   if($_server["request_method"] == "post") { // username , password sent form  $myusername = mysqli_real_escape_string($db,$_post['username']); $mypassword = mysqli_real_escape_string($db,$_post['password']);  $sql = "select id admin username = '$myusername' , passcode = '$mypassword'"; $result = mysqli_query($db,$sql); $row = mysqli_fetch_array($result,mysqli_assoc); $active = $row['active'];  $count = mysqli_num_rows($result);  // if result matched $myusername , $mypassword, table row must 1 row  if($count == 1) {     $_session['username'] = $myusername;     header("location: welcome.php"); }else {     $error = "your login name or password invalid";     header("location: login.php?error=".$error); } } else {  if (isset($_get['error'])) {     echo $_get['error']; }  ?> <html>  <head>     <title>login page</title>      <style type="text/css">         body {             font-family: arial, helvetica, sans-serif;             font-size: 14px;         }          label {             font-weight: bold;             width: 100px;             font-size: 14px;         }          .box {             border: #666666 solid 1px;         }     </style>  </head>  <body bgcolor="#ffffff">  <div align="center">     <div style="width:300px; border: solid 1px #333333; " align="left">         <div style="background-color:#333333; color:#ffffff; padding:3px;"><b>login</b></div>          <div style="margin:30px">              <form action="" method="post">                 <label>username :</label><input type="text" name="username" class="box"/><br/><br/>                 <label>password :</label><input type="password" name="password" class="box"/><br/><br/>                 <input type="submit" value=" submit "/><br/>             </form>              <div style="font-size:11px; color:#cc0000; margin-top:10px"><?php echo $error; ?></div>          </div>      </div>  </div>  </body> </html> <?php } ?> 

this session code

 <?php  session_start();  include('config.php');    $user_check = $_session['myusername'];   $ses_sql = mysqli_query($db,"select username admin username = '$user_check' ");   $row = mysqli_fetch_array($ses_sql,mysqli_assoc);   $login_session = $row['username'];   ?> 

redirected page

 <?php  include('session.php');  ?> <html>  <head> <title>welcome </title> </head>   <body>  <h1>welcome <?php echo $login_session; ?></h1>  <h2><a href = "logout.php">sign out</a></h2>  </body>   </html>  <?php  session_start();   if(session_destroy()) {  header("location: login.php");  }  ?> 

Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -