I have been picking up some PHP to get into Wordpress development and I was trying to build a login/logout system but there are a few problems,
So I've got index.php
<?php
ini_set("session.save_path", "/home/system/sessionData");
session_start();
include('functions.php')
?>
<?php if (isset($_SESSION['logged-in']) && $_SESSION['logged-in']) : ?>
<p> please login</p>
<form method="post" action="login.php">
Username <input type="text" name="username">
Password <input type="password" name="password">
<input type="submit" value="Logon">
</form>
<?php endif; ?>
</div>
<?php if(isset($_SESSION['logged-in']) && $_SESSION['logged-in'] == true) : ?>
just logged in content
<a href="logout.php" class="logout-link">Logout</a>
<?php endif; ?>
Then I've got login.php which is just basically getting data and validating it from a DB which is all working fine but when I logout and redirect my user back to index.php, I am not able to see any of the div's on index.php just a blank white page.
my logout.php
ini_set("session.save_path", "/home/system/sessionData");
session_start();
$_SESSION = array();
unset($_SESSION['username']);
unset($_SESSION['logged-in']);
session_destroy();
header('Location:index.php');
die;
If I add the following " $_SESSION['logged-in'] = ''; " at the top of my index.php, I'm able to see the content but the session is not saving obviously, I believe the whole problem has something to do with this? I have defined this session in my login.php should I define it again in index.php?
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…