ajax logout,php - AJAX Logout if Session has Expired - Stack Overflow

I have a number of AJAX calls that still partially work if the SESSION has expired.

eg: a contact us form will load, can be filled and appears to be sent but the AJAX call fails on the backend as SESSION variables don't exist.

I wanted to set a generic piece of PHP to check the session is still present like:

session_start();

But nothing happens with this in place.

I'm assuming that header() will only work when the page is loading - is this correct?

Therefore I assume I will need to get the AJAX call to return a success or failure on the session and do the re-directing from JQUERY.

Is this the best way to do this? Can header() redirect on an AJAX call? is there another way to get the redirect to work from an AJAX PHP call?

thx

* UPDATE *

Yes the page has already loaded. The AJAX call is a post page load function sending a contactus request. Therefore I assume header() is a no go from what I've read here. header() would have been good as it could have sat at the top of a large PHP script and generically responded to any request where the session was set.

Looks like I'll have to build a check in for each AJAX call that uses the session. can use a generic function. Is there a more simple way to log a user out when the session has expired on an AJAX site?

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值