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

查看:31
本文介绍了如果未登录,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 重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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