Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/259.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP登录不';行不通_Php_Session - Fatal编程技术网

PHP登录不';行不通

PHP登录不';行不通,php,session,Php,Session,我有一个登录屏幕,但似乎有问题 单击“登录”时,出现以下错误: 出现错误\u太多\u重定向 我不知道是什么原因造成的,有人知道吗 login.php: <?php include('db/login.php'); // Include Login Script if ((isset($_SESSION['email']) != '')) { header('Location: modal.php'); } ?> <!D

我有一个登录屏幕,但似乎有问题 单击“登录”时,出现以下错误:

出现错误\u太多\u重定向

我不知道是什么原因造成的,有人知道吗

login.php:

<?php
    include('db/login.php'); // Include Login Script
    if ((isset($_SESSION['email']) != '')) 
    {
    header('Location: modal.php');
    }
    ?>

    <!DOCTYPE html>
    <html lang="en">

        <head>
            <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
            <meta name="viewport" content="width=device-width, initial-scale=1.0">
            <title>Log In | DKTP</title>
            <link rel="stylesheet" href="css/login.css" type="text/css">
        </head>

    <body>

      <div class="wrap">
        <div class="fleft">

        </div>

     <center>

    <div id="login-form">
        <form method="post">
            <table align="left" width="32%">

        <tbody>

        <tr>
            <td><img src="img/logo.png" align="center"></td>
        </tr>

        <tr>
            <td> </td>
        </tr>
        <tr>
            <td> </td>
        </tr>

        <tr>
            <td>Aanmelden met DTKP account</td>
        </tr>

        <tr>
            <td> </td>
        </tr>


        <tr>
            <td><input type="text" name="email" placeholder="iemand@dktp.nl" required=""></td>
        </tr>

        <tr>
            <td><input type="password" name="password" placeholder="*******" required=""></td>
        </tr>

        <tr>
            <td> </td>
        </tr>

        <tr>
            <td><input name="submit" type="submit" value=" Login "></td>
        </tr>

        <tr>
            <div class="error"><?php echo $error;?></div>
        </tr>

        </tbody>
            </table>
        </form>
    </div>

     </center>

    </div>

    </body>
    </html>
<?php
session_start();
include("db/dbconnect.php"); //Establishing connection with our database

$error = ""; //Variable for storing our errors.
if(isset($_POST["submit"]))
{
if(empty($_POST["email"]) || empty($_POST["password"]))
{
$error = "Both fields are required.";
}else
{
// Define $username and $password
$username=$_POST['email'];
$password=$_POST['password'];

// To protect from MySQL injection
$username = stripslashes($username);
$password = stripslashes($password);
$username = mysqli_real_escape_string($db, $username);
$password = mysqli_real_escape_string($db, $password);
$password = md5($password);

//Check username and password from database
$sql="SELECT * FROM users WHERE email='$username' and password='$password'";
$result=mysqli_query($db,$sql);
$row=mysqli_fetch_array($result,MYSQLI_ASSOC);

//If username and password exist in our database then create a session.
//Otherwise echo error.

if(mysqli_num_rows($result) == 1)
{
$_SESSION['username'] = $login_user; // Initializing Session
header("location: modal.php"); // Redirecting To Other Page
}else
{
$error = "Incorrect username or password.";
}

}
}

?>

登录| DKTP
Aanmelden符合DTKP账户
db/login.php:

<?php
    include('db/login.php'); // Include Login Script
    if ((isset($_SESSION['email']) != '')) 
    {
    header('Location: modal.php');
    }
    ?>

    <!DOCTYPE html>
    <html lang="en">

        <head>
            <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
            <meta name="viewport" content="width=device-width, initial-scale=1.0">
            <title>Log In | DKTP</title>
            <link rel="stylesheet" href="css/login.css" type="text/css">
        </head>

    <body>

      <div class="wrap">
        <div class="fleft">

        </div>

     <center>

    <div id="login-form">
        <form method="post">
            <table align="left" width="32%">

        <tbody>

        <tr>
            <td><img src="img/logo.png" align="center"></td>
        </tr>

        <tr>
            <td> </td>
        </tr>
        <tr>
            <td> </td>
        </tr>

        <tr>
            <td>Aanmelden met DTKP account</td>
        </tr>

        <tr>
            <td> </td>
        </tr>


        <tr>
            <td><input type="text" name="email" placeholder="iemand@dktp.nl" required=""></td>
        </tr>

        <tr>
            <td><input type="password" name="password" placeholder="*******" required=""></td>
        </tr>

        <tr>
            <td> </td>
        </tr>

        <tr>
            <td><input name="submit" type="submit" value=" Login "></td>
        </tr>

        <tr>
            <div class="error"><?php echo $error;?></div>
        </tr>

        </tbody>
            </table>
        </form>
    </div>

     </center>

    </div>

    </body>
    </html>
<?php
session_start();
include("db/dbconnect.php"); //Establishing connection with our database

$error = ""; //Variable for storing our errors.
if(isset($_POST["submit"]))
{
if(empty($_POST["email"]) || empty($_POST["password"]))
{
$error = "Both fields are required.";
}else
{
// Define $username and $password
$username=$_POST['email'];
$password=$_POST['password'];

// To protect from MySQL injection
$username = stripslashes($username);
$password = stripslashes($password);
$username = mysqli_real_escape_string($db, $username);
$password = mysqli_real_escape_string($db, $password);
$password = md5($password);

//Check username and password from database
$sql="SELECT * FROM users WHERE email='$username' and password='$password'";
$result=mysqli_query($db,$sql);
$row=mysqli_fetch_array($result,MYSQLI_ASSOC);

//If username and password exist in our database then create a session.
//Otherwise echo error.

if(mysqli_num_rows($result) == 1)
{
$_SESSION['username'] = $login_user; // Initializing Session
header("location: modal.php"); // Redirecting To Other Page
}else
{
$error = "Incorrect username or password.";
}

}
}

?>

db/dbconnect.php:

<?php

define('DB_SERVER', 'localhost');
define('DB_USERNAME', 'root');
define('DB_PASSWORD', 'Iamthebest1009');
define('DB_DATABASE', 'dktp');
$db = mysqli_connect(DB_SERVER,DB_USERNAME,DB_PASSWORD,DB_DATABASE);

?>

modal.php:

<?php
include("db/check.php"); 

?>

<!DOCTYPE html>
<html>
  <head>
    <link rel="stylesheet" href="css/modal.css" type="text/css" />
    <link href='//fonts.googleapis.com/css?family=Philosopher' rel='stylesheet'>
  </head>
<body>

<h1 class="hello">Hello, <em><?php echo $login_user;?>!</em></h1>
<br><br><br>
<a href="logout.php" style="font-size:18px">Logout?</a>

<!-- Trigger/Open The Modal -->
<button id="btn">Thema</button>

<!-- The Modal -->
<div id="myModal" class="modal">

  <!-- Modal content -->
  <div class="modal-content">

    <div class="modal-header">
      <span class="close">&times;</span>
      <h2>Kies thema</h2>
    </div>

      <div class="modal-body">
        <a href="tablenorm.php"><button id="btn2">Normen</button></a>
        <a href="tableorden.php"><button id="btn2">Ordenen</button></a>
        <a href="tableclust.php"><button id="btn2">Clusteren</button></a>
      </div>

    </div>

  </div>

<script src="js/modal.js"></script>

</body>
</html>

你好



西玛 &时代; 基斯·西玛
db/check.php

<?php
include('db/dbconnect.php');
session_start();
$user_check=$_SESSION['email'];

$sql = mysqli_query($db,"SELECT email FROM users WHERE email='$user_check' ");

$row=mysqli_fetch_array($sql,MYSQLI_ASSOC);

$login_user=$row['email'];

if(!isset($user_check))
{
header("Location: modal.php");
}
?>

login.php中的

改变

if ((isset($_SESSION['email']) != '')) 
致:

关于“为什么”这应该解决问题:

在php手册中:


isset
如果var存在且值不是NULL,则返回TRUE。否则为FALSE

代码太多。您需要自己更好地解决这个问题。我们不是调试器。您需要隔离问题并从中进行调试。如果你陷入困境,请清楚地解释什么东西不适合你。我建议你读一个好的问题和答案。另外,请务必阅读。
如果((isset($\u SESSION['email'])!=”)
为假阳性。它需要分为两种不同的情况。一个用来检查它是否已设置,另一个用来检查它是否为空。您不应该使用md5来使用此代码,因为它不安全。你是在上网吗?可能是重定向循环?甚至可能是
.htaccess
中某个地方的mod重写,谁知道呢。我认为OP已经越狱了。事实上,如果他们想检查这两种情况,应该将其设置为两种不同的条件。