doulin6088 2013-01-03 07:14
浏览 89
已采纳

使用Ajax和标头重定向记录错误

I am trying to make something where if a user tries to execute a function in my system when they are not logged in, it will popup a message saying they can't do it because they aren't logged in. They are then sent to the login screen when they press ok.

I also want it to redirect users back to the login screen if they type the url in directly, but this time without an error message.

I have:

$components = explode('/', $url, 3) ;

if(!isset($_SESSION['loggedin']) && $components[0] != 'access' && $components[0] != 'login')
    {

        echo json_encode('{"error": 2000, "msg": "You must be logged in to do that."}') ;
        return false ;
}

Which is fine for Ajax, but wouldn't work if the url was typed in. The $components[0] != 'access' etc is to just stop this condition executing if the user is on the login screen.

How can I do this without the header location effecting the Ajax call and also not simply echoing the error message when the user visits a forbidden url?

  • 写回答

2条回答 默认 最新

      报告相同问题?

      相关推荐 更多相似问题

      悬赏问题

      • ¥30 VB6.0操作 webview2内核的浏览器如何精确实现网页弹窗处置
      • ¥15 pr导出的视频打不开,提示“缺少编解码器”怎么解决
      • ¥15 html里js获取php参数值不成功,帮改代码
      • ¥20 如何控制ant design的InputNumber组件 最多输入5位小数
      • ¥15 c语言学生基本信息管理系统
      • ¥100 火车头采集器采集求解
      • ¥88 关于#运行时间 时间重叠 和非重叠#的问题,如何解决?
      • ¥15 C语言,密切接触者追踪
      • ¥20 关于计算机网络问题,请附带讲解
      • ¥30 自动识别图像目标并判断