-1
このコードにループがあります(ユーザーはログインページに戻されます)。問題部分は次のとおりですセッション/認証ループ
else if (!$session_id){
//if user is not logged in, send to the login page
header("Location:" . $Config_live_site . "/user_events/login.php");
exit;
}
これはすべてのネストされたif文と関係があります。上記の "else if"が削除された場合、ユーザーはログインでき、すべてのセッション機能が正常に動作します。
//check if the user has clicked on a submit button in a login form in login.php
if (isset($_POST['submit'])) {
$username = $_POST['username'];
$pass = $_POST['password'];
if (!$username) {
echo "<script>alert('Please enter username'); document.location.href='index.php?option=login$string_2';</script>\n";
}
if (!$pass) {
echo "<script>alert('Please enter a password'); document.location.href='index.php?option=login$string_2';</script>\n";
}
else {
$pass = md5($pass);
}
//set up user object and start a new session
$user = new user();
$database->get_user(&$user, $username, '1');
if (!strcmp($user->user_pass, $pass)) {
session_name('login');
session_start();
$logintime = time();
$session_id = md5("$user->username$user->user_type$logintime");
$database->set_session($user, $session_id, $logintime);
$_SESSION['session_id'] = $session_id;
$_SESSION['session_username'] = $user->username;
$_SESSION['session_usertype'] = $user->user_type;
$_SESSION['session_logintime'] = $logintime;
session_write_close();
// cannot using mosredirect as this stuffs up the cookie in IIS
if ($suboption) {
echo "<script>document.location.href='index.php?$string';</script>\n";
} else {
echo "<script>document.location.href='index.php?option=subscriber_home';</script>\n";
}
exit();
} else {
echo "<script>alert('Incorrect Username and Password, please try again'); document.location.href='index.php?option=subscribe$string_2';</script>\n";
exit();
}
}
else if (!$session_id){
//if user is not logged in, send to the login page
header("Location:" . $Config_live_site . "/user_events/login.php");
exit;
}
//session starts
session_name('login');
session_start();
if ($option == 'logout') {
require 'logout.php';
exit();
}
$user = new user();
$user->username = $_SESSION['session_username'];
$user->user_type = $_SESSION['session_usertype'];
$session_id = $_SESSION['session_id'];
$logintime = $_SESSION['session_logintime'];
私はチェックマークをクリックしなければならないことを知っていましたか?今私は知っている。 – Natalia
あなたはなぜ自分のセッションIDを作っていますか? PHPは 'session_start()'を実行したときにすでにそれを行い、 'session_id()'で値を取得できます。 –
問題は、セッションを設定する前にsession_idを使用しようとしていることです。 –