简体   繁体   English

重定向到登录页面

[英]Redirecting to a login page

I am creating a demo admin panel where an administrator will have to login in order to have access to the records of an example food business' order history, however I can easily just type in the url of this 'private' page which is only supposed to be accessed by the logged in administrator.我正在创建一个演示管理面板,管理员必须登录才能访问示例食品企业的订单历史记录,但是我可以轻松地输入这个“私人”页面的 url由登录的管理员访问。 How would I make it so that if a user where to type in this url that they will be redirected to the login page for access if they are not logged in?如果用户在哪里输入此 url,我将如何做到这一点,如果他们未登录,他们将被重定向到登录页面进行访问?

I believe using php sessions could be on the right track?我相信使用 php 会话可能会走上正轨吗? Any advice would be great任何建议都会很棒

In the private page check presence of the session if the session is not set then the user has not logged in redirect to the logging in page from there.在私有页面中检查 session 是否存在,如果未设置 session,则用户尚未登录,从那里重定向到登录页面。 You can redirect using header('location':'login.php');您可以使用 header('location':'login.php'); 重定向

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM