【发布时间】:2016-02-18 10:18:23
【问题描述】:
我需要帮助。我有一个使用 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);
});
}
注销.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");
?>
请帮我解决这个问题。
【问题讨论】:
标签: javascript php mysql angularjs session