PHP重定向(如果未登录) [英] PHP redirect if not logged in

查看:168
本文介绍了PHP重定向(如果未登录)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试使以下功能在我的网站上起作用,但是我对此颇为挣扎.也许你们中的一个可以帮助我吗?

I have been trying to make this following functionality work on my website, however I'm kinda struggling with it. Perhaps one of you can help me out?

我正在开发一个网站,除非您登录,否则该网站必须无法访问(当然登录除外).如果用户未登录,我试图自动重定向到登录页面.我正在使用目前是HTML,CSS和PHP.

I am developing a website which must be inaccessible (except the login of course) unless you are logged in. I was trying to make an automatic redirect to the login page if the user isn't logged in. I'm using HTML, CSS, and PHP at the moment.

如果需要我的其他消息来源,请告诉我,我将暂时在线托管该网站.

If my remaining source is needed please tell me, I'll temporarily host the site online.

推荐答案

如果您不使用任何框架,请尝试以下简单操作:

If you're not using any frameworks, try simply:

if(!isset($_SESSION['login'])){ //if login in session is not set
    header("Location: http://www.example.com/login.php");
}

会话参数和重定向位置取决于您在Web项目中使用的体系结构.

The session parameter and the redirect location depends on the architecture that you're using on your web project.

这篇关于PHP重定向(如果未登录)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆