无需登录即可访问页面

时间:2015-04-23 13:26:39

标签: php admin visitors

我有一个登录'页。当人们使用数据库中的用户名和密码的正确组合登录时,他们将被定向到另一个页面(' input.html')。如果组合错误,则会出错。

如果没有登录,我只需更改网址的名称(从' login.php'到' input.html')并访问该页面。我只希望管理员和用户访问该页面,而不仅仅是访问者'没有帐户。

我的代码是我的' login.php'。

<?php
session_start();

$host = "localhost";
$user = "332547";
$pass = "cvEsbduv";
$db = "332547db";

mysql_connect($host, $user, $pass);
mysql_select_db($db);




if (!empty($_POST)) {
    $username = $_POST['username'];
    $password = $_POST['password'];
            $sql = "SELECT * FROM inloggen2 WHERE username='".$username."'      AND password='".$password."' LIMIT 1";




            $res = mysql_query($sql);
            if(mysql_num_rows($res) == 1) {
                header('location: input.html');
                exit ();
            }else {

                echo "Niet goed ingelogd. Keer alstubliefd terug naar de vorige pagina.";

                header('location: foumelding.php');
                exit();
            }
}
?>




<html>

<head>
<title>Inloggen</title>
</head>

<body>
<table border="1">
  <tr>
    <td align="center">Inlogggen</td>
  </tr>
  <tr>
    <td>
      <table>

        <form method="post" action="login.php">
    Gebruikersnaam: <input type="text" name="username" required/> <br /><br />
    Wachtwoord: <input type="password" name="password" required/> <br /><br />
<input type="submit" name="submit" value="Log in" />
</form>
        </table>
      </td>
    </tr>
</table>
</body>
</html>    

2 个答案:

答案 0 :(得分:1)

您需要将index.html转换为php文件,并为登录用户添加支票。

你应该阅读更多关于php的内容,也许在php中阅读一些关于简单登录系统的教程:https://www.google.de/search?q=php+simple+login+system

答案 1 :(得分:0)

你需要在索引上使用php代码。 html php

更具体:Sessions

我发现您已在此页面上使用session_start();了。也可以在index.php上使用它,然后继续学习/使用Sessions。

<强> OFFTOPIC:

  • 您可以mysql injection开放。
  • 不要使用mysql使用mysqli或PDO代替
  • 不要将密码存储为纯文本。 Hash them etc...(只需谷歌如何在数据库中存储密码)。
  • 你有很多拼写错误(我假设)如:

    echo "Niet goed ingelogd. Keer alstublief d t terug naar de vorige pagina.";

    和(可能):

    header('location: foumelding.php');不应该是:header('location: foutmelding.php');

    <td align="center">Inlogggen</td>不应该是:<td align="center">Inloggen</td>

相关问题