当我登录该网站时,我转到blabla.com/login /
HTML:
<?php
if(isset($_POST["login"]))
{
$logind = $mebe->logind();
}
?>
<form action="<?php $_SERVER['PHP_SELF'];?>" method="post">
<table width="100%" cellpadding="0" cellspacing="0">
<tr>
<td>Brugernavn</td>
<td><input type="text" name="brugernavn" maxlength="300"></td>
</tr>
<tr>
<td>Adgangskode</td>
<td><input type="password" name="pass"></td>
</tr>
<tr>
<td></td>
<td><input type="submit" name="login" value="Log ind"></td>
</tr>
</table>
</form>
PHP:(登录功能在这里:)
function logind()
{
if($_POST["brugernavn"] == "")
{
$error = 1;
}
if($_POST["pass"] == "")
{
$error = 1;
}
if($error != 1)
{
if ($stmt = $this->mysqli->prepare("SELECT id, brugernavn, rank, ranknavn FROM bruger WHERE brugernavn = ? AND adgangskode = ?"))
{
$stmt->bind_param('ss', $brugernavn, $adgangskode);
$brugernavn = $_POST["brugernavn"];
$adgangskode = sha1($_POST["pass"]);
$stmt->execute();
$stmt->store_result();
$stmt->bind_result($id, $brugernavn, $rank, $ranknavn);
$stmt->fetch();
$count = $stmt->num_rows;
$stmt->close();
if($count > 0)
{
$_SESSION["logged_in"] = true;
$_SESSION["id"] = $id;
$_SESSION["brugernavn"] = $brugernavn;
$_SESSION["rank"] = $rank;
$_SESSION["ranknavn"] = $ranknavn;
if($_SESSION["logged_in"] == true and $_SESSION["rank"] >= 1)
{
?>
<script language="javascript" type="text/javascript">
window.location.href = "/wall/";
</script>
<?php
}
else
{
echo "Fejl..";
}
}
else
{
?>
<div class="alert error fade in">
<p>Forkert Brugernavn / Password.</p>
<a class="close" data-dismiss="alert" href="#" aria-hidden="true"><i class="fa fa-times-circle"></i></a>
</div>
<?php
}
}
//fejl
else
{
echo 'Der opstod en fejl i erklæringen: ' . $this->mysqli->error;
}
}
else
{
?>
<div class="alert error fade in">
<p>Forkert, Prøv igen!</p>
<a class="close" data-dismiss="alert" href="#" aria-hidden="true"><i class="fa fa-times-circle"></i></a>
</div>
<?php
}
}
如果我使用标题('Location:/ wall /');然后它将只是在登录页面上,并没有显示一个人以某种方式登录该网站。
EIDT
它关闭网站 - 仅限用户;
<?php
session_start();
include("phpFiler/fun.php");
$mebe = new mebe;
$db = $mebe->db_c();
error_reporting(E_ERROR);
if($_SESSION["logged_in"] == true)
{
?>
并向alle用户开放
<?php
session_start();
include("phpFiler/fun.php");
$mebe = new mebe;
$db = $mebe->db_c();
error_reporting(E_ERROR);
?>