我需要一个帮助。我有一个使用Angular.js,PHP和MySQL的登录模块。这里我需要用户在15mins
之后没有在网站内做任何事情它将自动注销并且会话将会破坏。我正在解释下面的代码。
$http({
method: 'GET',
url: 'php/Login/session.php',
headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
}).then(function successCallback(response){
//console.log('session',response);
$scope.userType=response.data[0].first_name+" "+response.data[0].last_name;
},function errorCallback(response) {
$state.go('/',{}, { reload: true });
});
$scope.logout=function(){
$http({
method: 'POST',
url: 'php/Login/logout.php',
headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
}).then(function successCallback(response){
//console.log('session',response);
//alert(response);
},function errorCallback(response) {
//console.log('session',response);
//alert(response);
});
}
logout.php:
require_once '../../include/dbconfig.php';
$postdata = file_get_contents("php://input");
session_unset();
session_destroy();
if(session_destroy()){
echo "User logged out successfully";
}else{
echo "User could not log out successfully";
}
session.php文件:
require_once '../../include/dbconfig.php';
$result = mysqli_query($connect, "SELECT * FROM db_user WHERE user_id=". $_SESSION["admin_id"]);
$data = array();
while ($row =mysqli_fetch_assoc($result)) {
$data[] = $row;
}
if($data){
print json_encode($data);
}else{
header("HTTP/1.0 401 Unauthorized");
print "session has destroyed";
}
dbconfig.php:
<?php
$lifetime=900;
session_set_cookie_params($lifetime);
session_start();
$con = mysql_connect("localhost", "root", "********");
mysql_select_db('go_fasto', $con);
$connect = mysqli_connect("localhost", "root", "*******", "go_fasto");
?>
请帮我解决这个问题。
答案 0 :(得分:0)
$lifetime=900;
session_set_cookie_params($lifetime);
session_start();
&#13;
这里15分钟到900秒......所以在开始之前提到会话的最长寿命...所以15分钟之后如果没有动作则会话将会到期