Reputation: 691
<!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>
The code above is supposed to be a secure page, which will use sessions. The problem is when the login is processed, it checks wether the password is good or not, but doesn't set the session (that or my if
condition is broken).
Any ideas ? :/
Upvotes: 0
Views: 83
Reputation: 1863
php session_start(); has to be invoked before everything else, so place it before html element.
Upvotes: 1
Reputation: 4089
to check whether session exists or not you need to use isset()
So
change
if($_SESSION['admin'])
to
if(isset($_SESSION['admin']))
Upvotes: 1