【问题标题】:session_destroy() not working when called from angular从角度调用时 session_destroy() 不起作用
【发布时间】:2016-04-01 04:26:07
【问题描述】:

我正在从 Angular 调用 logout.php 页面:

$scope.logout = function(){
        $cookies.remove("isLoggedIn");
        $http({ url : "./include/logout.php" }).then(function(response) {
alert(response.data)});
        window.open("indexB.html", "_self");
            }

这是 php:

<?php
        echo 'test';
        session_start();
        session_destroy();
        session_unset();
        unset($_SESSION); 
?>

当我单击注销按钮并调用注销函数时,我的“isLoggedIn”cookie 被删除,我收到“测试”警报,但 PHP 会话 cookie 不会删除。

【问题讨论】:

  • 要使用基于 cookie 的会话,必须在向浏览器输出任何内容之前调用 session_start()。
  • 我创建了一个名为 start.php 的文件,该文件在任何 html 输出到浏览器之前运行,启动会话,然后重定向到调用注销功能的页面。我仍然看到 and session_destroy() 仍然不起作用。

标签: php angularjs


【解决方案1】:

前段时间我也有同样的问题,解决我的问题的是:

$domain = "yourdomainhere.com";
session_start();
$session = session_id(); 
setcookie("userid", $session, time() + (10 * 365 * 24 * 60 * 60), "/");

希望对你有帮助

【讨论】:

  • 抱歉,您能解释一下这是做什么的以及如何替换典型的 php 会话吗?我可以在此 cookie 中安全地存储用户 ID 吗?
猜你喜欢
  • 1970-01-01
  • 2018-08-19
  • 2015-11-24
  • 2013-04-29
  • 1970-01-01
  • 2018-07-14
  • 2014-01-08
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多