ログインシステムを作成していて、動作するようになりましたが、Web サイトのログアウト機能を作成するのに苦労しています。実際にはまだホストされていないため、セキュリティは後で提供されます。session_destroy と unset のさまざまな使用法を試しましたが、機能しません。どんな助けでも大歓迎です。
私のPHP
<?php
session_start();
/*This is the equivalent of login.php*/
$database = "forum"; // the name of the database.
$server = "localhost"; // server to connect to.
$db_user = "root"; // mysql username to access the database with.
$db_pass = ""; // mysql password to access the database with.
$table = "members"; // the table that this script will set up and use.
$link = mysql_connect($server, $db_user, $db_pass);
mysql_select_db($database,$link);
if (isset($_POST['fsubmitted'])) {
// Get the data passed from the form
$username = $_POST['username'];
$pass = $_POST['pass'];
// Do some basic sanitizing
$username = stripslashes($username);
$pass = stripslashes($pass);
$encryptedpass = md5($pass);
$sql = "SELECT * from members where username = '$username' and password = '$encryptedpass'";
$result = mysql_query($sql);
$count = 0;
$count = mysql_num_rows($result);
if ($count == 1) {
$_SESSION['loggedIn'] = "true";
header("Location: index.php"); // This is wherever you want to redirect the user to
exit();
} else {
$_SESSION['loggedIn'] = "false";
echo '<div class="errormsgbox">Your username and password combo was incorrect!</div>';
var_dump($result);
echo $sql;
}
}
if ($_SESSION['loggedIn'] = "true") {
echo '<div class="success">You are now logged in!</div>';
}
if (isset($_SESSION['loggedin']) && (time() - $_SESSION['loggedin'] > 1800)) {
// last request was more than 30 minutes ago
session_unset(); // unset $_SESSION variable for the run-time
session_destroy(); // destroy session data in storage
}
$_SESSION['loggedin'] = time(); // update last activity time stamp
?>