<!DOCTYPE html>
<?php
session_start();
?>
<!-- ERA DSIGN DESIGN BY SHOWTIME -->
<!-- COPYRIGHT 2014 CristianD DESIGN -->
<head>
<title>eRa Design</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="container">
<div class="menu">
<a href="index.html"><div class="item">Home</div></a>
<a href="team.html"><div class="item">The Team</div></a>
<a href="portofolio.html"><div class="item">Portofolio</div></a>
<a href="recruitment.html"><div class="item">Recruitment</div></a>
<a href="store.php"><div class="item">Design Store</div></a>
</div>
<div class="logo">
<img src="logo.png" alt="">
</div>
<div class="article">
<?php
if($_SESSION['admin']):
?>
<h2>Test</h2>
<?php
else:
?>
<form action="view.php" method="post">
<input type="password" name="password" class="sharp">
<input type="submit" class="button" value="Login">
</form>
<?php
if($_POST['password'] == 'luridpls')
$_SESSION['admin'] = 'logged';
else echo "Wrong Password!";
endif;
?>
</div>
<div class="footer">
(C) eRa Design - 2014<br>
<em>Designed by ShowTime</em>
</div>
</div>
</body>
上面的代码应该是一个安全页面,它将使用会话。问题是当处理登录时,它会检查密码是否良好,但是没有设置会话(那个或我的if
条件被破坏了。)
有什么想法吗? :/
答案 0 :(得分:3)
尝试
if(isset($_SESSION['admin']))
答案 1 :(得分:1)
检查会话是否存在,您需要使用isset()
所以
变化
if($_SESSION['admin'])
到
if(isset($_SESSION['admin']))
答案 2 :(得分:1)
php session_start();必须在其他所有内容之前调用它,所以将它放在html元素之前。