그래서 사용자 정의 사용자 클래스를 호출하는 로그인 스크립트가 있는데 사용자가 로그인하면 세션이 설정됩니다. redict에 var 덤프를 login.php 페이지로 보내면 사용자가 성공적으로 로그인했음을 알리고 친절한 환영 메시지가 표시됩니다.PHP 세션 로그인이 있지만 다른 페이지에없는 경우
세션을 설정하는 코드는 다음 login.php 페이지에 대해 잘 작동
private function setIsLoggedIn($credentials) {
if (!isset($_SESSION)) {
session_start();
}
$_SESSION['verified'] = $credentials;
session_write_close();
}
는, 함수의 인수는 다음과 같습니다
// assign user info from db to the session
$this->setIsLoggedIn(array('UserId' => $user->userid,
'UserName' => $user->username,
'RoleId' => $user->roleid));
이가 login.php입니다 양식 게시 뒤로
// if the form was submitted
if (isset($_POST['submit'])) {
// Set local variables from $_POST array elements (userlogin and userpassword) or empty strings
$userLogin = (isset($_POST['userlogin'])) ? trim($_POST['userlogin']) : '';
$userPassword = (isset($_POST['userpassword'])) ? trim($_POST['userpassword']) : '';
//assign values to array and get user object
$authArray = array('UserName' => $userLogin, 'Password' => $userPassword);
$user = new Users($authArray);
if ($user->getUserId() > 0) { //If credentials check out
// redirect the user to SESSION value set from common class
if (isset($_SESSION['prev_page']))
{
header('location:' . $_SESSION['prev_page']);
exit;
}
else
{
// Otherwise, assign error message to $msg
$msg = '<p><strong>Thank your for logging in.<br />You may now visit tools that are in development.</strong></p>';
}
}
else
{
// Otherwise, assign error message to $msg
$msg = '<p><strong>Sorry, that username and password are not recognized.<br />Please try again.</strong></p>';
}
}
이제 다른 페이지로 이동하여 $ var_dump ($ _ SESSION);
$_SESSION['prev_page'] = "http://".$_SERVER[SERVER_NAME]."/id/AphID/";
이 파일의 첫 번째 줄은 다음과 같습니다 :
Session Support enabled
Registered save handlers files user
Registered serializer handlers php php_binary wddx
Directive Local Value Master Value
session.auto_start Off Off
session.bug_compat_42 On On
session.bug_compat_warn On On
session.cache_expire 180 180
session.cache_limiter nocache nocache
session.cookie_domain no value no value
session.cookie_httponly Off Off
session.cookie_lifetime 0 0
session.cookie_path//
session.cookie_secure Off Off
session.entropy_file /dev/urandom /dev/urandom
session.entropy_length 16 16
session.gc_divisor 1000 1000
session.gc_maxlifetime 1440 1440
session.gc_probability 1 1
session.hash_bits_per_character 5 5
session.hash_function 0 0
session.name PHPSESSID PHPSESSID
session.referer_check no value no value
session.save_handler user files
session.save_path /tmp /tmp
session.serialize_handler php php
session.use_cookies On On
session.use_only_cookies Off Off
session.use_trans_sid 1 1
: 여기
<?php
session_start();
var_dump($_SESSION);
내 PHP 세션 설정입니다 페이지에서 내가하고 있어요 때문에 나는 항상이, 다른 뭔가를 얻을
그래서 기본적으로 내 세션은 실제로 로그인 페이지에만 존재하며 그 밖의 어디에도없고 Session_start()를 호출하면됩니다. 나는 항상 다른 세션을 얻는다. 어떤 아이디어?
를 호출 할 수있는 세션을 복원? session_write_close 호출 후에 설정하면 효과가 없습니다. –