简体   繁体   English

Xampp登录php验证问题

[英]Login php verification Problem with Xampp

I am trying to verify the login of a website using php by querying the database table .我试图通过查询数据库表来验证使用 php 的网站的登录。 It is creating an error parsing the session in the login.php.它在解析 login.php 中的会话时产生错误。 The website is all hosted on XAMPP.该网站全部托管在 XAMPP 上。 This is just a trial website.这只是一个试用网站。 This is my first time coding in PHP, honestly just a week in.这是我第一次用 PHP 编码,老实说才一周。

I've tried to modify the $global variables.我试图修改 $global 变量。 Is it because xampp is running on MariaDB instead of sql, but that makes no sense because this is PHP and the create_table是不是因为 xampp 在 MariaDB 而不是 sql 上运行,但这没有意义,因为这是 PHP 和 create_table

This is the login
<html form
<div class="loginbox">
<img src="images/log.png" class="log">
<h1> Login </h1>
<form  action="login.php" method="post">

<div class="name">
<label for ="name"> Username/E-mail:</label>
<input type="text" id="name" name="username" placeholder="Enter  
 Username/E-mail">    
</div>

<div class="password">
<label for="password"> Password:</label>
<input type="password" id="password" name="password" 
 placeholder="Enter Password">
</div>

<div>
<button type="submit"  >Login</button>
</div>
</form> 

</div>

And this is the table created for signup.
    $persontable= "CREATE TABLE IF NOT EXISTS users.Person(
    Userid                  INTEGER UNSIGNED AUTO_INCREMENT PRIMARY KEY,
    Firstname               VARCHAR(20) NOT NULL,
    Lastname                VARCHAR(20) NOT NULL,
    Username                VARCHAR(30) NOT NULL,
    Email                   VARCHAR(30) NOT NULL,
    Password                VARCHAR(20) NOT NULL,
    Dateofbirth             DATE        NOT NULL,
    Address                 VARCHAR(50) NOT NULL,
    City                    VARCHAR(50) NOT NULL,
    Zipcode                 VARCHAR(20),)";

    if (!(mysqli_query($handler,$persontable))){
        die("Account has not been created successfully:". 
    mysqli_error($handler)); }
    else{echo "Account has been created succesfully"}

And this is the code of login<php
  <?php
  $servername = "127.0.0.1";
  $username = "root";
  $password = "";
  /** Define variable to perform connection to the server*/
  $handler = mysqli_connect($servername, $username, $password);

  $errors = array();
  session_start();
  /** To perform authentication of login with the database*/

  if(empty($_POST['username'])){
        $this->errors[] = "Username field was empty.";
  } elseif (empty($_POST['password'])) {
        $this->errors[] = "Password field was empty.";
  }
  elseif(isset($_POST['username']) && isset($_POST['password'])){   
   $user=$_POST['username'];  
   $pass=$_POST['password'];  

   $handler or die(mysqli_error());  
   mysqli_select_db($handler,'users') or die("Cannot select DB");  

   $query=mysqli_query($handler,"SELECT Username,Email,Password 
    FROM person WHERE username='".$user."' OR email='".$user."'");  
    $numrows = mysqli_num_rows($query);  
    /**The old code is stated below here
    if ($result_of_login_check->num_rows == 1)
     */
     /**The Problem Starts here*/
     if ($numrows ==1){  
     if (password_verify($_POST['password']) {
     // write user data into PHP SESSION (a file on your 
     server)
     /**The Problem Starts here*/
     $_SESSION['user_name'] = $result_row->user_name;
     $_SESSION['user_email'] = $result_row->user_email;
     $_SESSION['user_login_status'] = 1;
     } else {
     $query->errors[] = "Wrong password or username. Try again.";
     }
     } 
     } 
     ?>

<?php session_start(); ?> <?php session_start(); ?> try this to top of login.php and make sure you have start session on every page <?php session_start(); ?>试试这个到 login.php 的顶部,并确保你在每个页面上都有启动会话

<?php session_start();?>
<?php
$servername = "127.0.0.1";
$username = "root";
$password = "";
/** Define variable to perform connection to the server*/
$handler = mysqli_connect($servername, $username, $password);
$errors = array();

/** To perform authentication of login with the database*/
if(empty($_POST['username'])){
$this->errors[] = "Username field was empty.";
} elseif (empty($_POST['password'])) {
$this->errors[] = "Password field was empty.";
}
elseif(isset($_POST['username']) && isset($_POST['password'])){
$user=$_POST['username'];
$pass=$_POST['password'];
$handler or die(mysqli_error());
mysqli_select_db($handler,'users') or die("Cannot select DB");
$query=mysqli_query($handler,"SELECT Username,Email,Password
FROM person WHERE username='".$user."' OR email='".$user."'");
$numrows = mysqli_num_rows($query);
/**The old code is stated below here
if ($result_of_login_check->num_rows == 1)
*/
/**The Problem Starts here*/
if ($numrows ==1){
if (password_verify($_POST['password']) {
// write user data into PHP SESSION (a file on your
server)
/**The Problem Starts here*/
$_SESSION['user_name'] = $result_row->user_name;
$_SESSION['user_email'] = $result_row->user_email;
$_SESSION['user_login_status'] = 1;
} else {
$query->errors[] = "Wrong password or username. Try again.";
}
}
}
?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM