PHP redirect if not logged in(如果未登录,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");
}
会话参数和重定向位置取决于您在网络项目中使用的架构.
The session parameter and the redirect location depends on the architecture that you're using on your web project.
这篇关于如果未登录,PHP 重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如果未登录,PHP 重定向
基础教程推荐
- 有什么方法可以用编码 UTF-8 而不是 Unicode 返回 PHP`json_encode`? 2021-01-01
- YouTube API v3 点赞视频,但计数器不增加 2022-01-01
- 在PHP中根据W3C规范Unicode 2022-01-01
- 学说 dbal querybuilder 作为准备好的语句 2022-01-01
- 如何在 Laravel 5.3 注册中添加动态下拉列表列? 2021-01-01
- 如何在 Laravel 中使用 React Router? 2022-01-01
- PHP 类:全局变量作为类中的属性 2021-01-01
- 如何替换eregi() 2022-01-01
- PHP PDO MySQL 查询 LIKE ->多个关键词 2021-01-01
- Cron Jobs 调用带有变量的 PHP 脚本 2022-01-01
