How can I redirect to home when user click on back

2019-09-13 10:30发布

I was wondering how can I redirect users to my hompage after they logged out when they hit the back button, kind of like facebook does. I was playing around with some javascript but nothing seemed to work.

PS: This will be for a Wordpress theme.

3条回答
乱世女痞
2楼-- · 2019-09-13 11:06
叼着烟拽天下
3楼-- · 2019-09-13 11:07

Javascript seems like the way to do it. Simply check if the user is logged and if not, do a redirect to the home page via a document.location = "http://my.home.page";

I guess that you have the session in PHP too so you could just do the redirect there instead of relying on Javascript.

header ('Location: http://your.home.page');
查看更多
姐就是有狂的资本
4楼-- · 2019-09-13 11:09

If you use sessions, you can check if the user is logged in when viewing an authenticated page, and if not, send the headers to your homepage.

查看更多
登录 后发表回答