简体   繁体   English

重定向用户到登录页面

[英]Redirecting Users to Login Page

I have been coding a content-based website. 我一直在编码基于内容的网站。 I want to lock some hyperlinks with a username and password. 我想用用户名和密码锁定一些超链接。

For other open links I used: 对于其他打开的链接,我使用了:

echo '<a href='news1.php?id=$id>'.$row['heading'].'</a>';

I want the users to click on the links, which will redirect them to the login page. 我希望用户单击链接,这会将他们重定向到登录页面。

You have missing the single quote in your string. 您在字符串中缺少单引号。

Try this 尝试这个

echo '<a href="news1.php?id='.$id.'">'.$row['heading'].'</a>';

Are you using any php framework, it yes, it has the mechanism to redirect a user to the login page if he has not logged in. If you are not using frameworks, then you should check user's login status (probably in news1.php) when they click the above link and redirect to the login page if they've not logged in. 您是否在使用任何php框架,是的,如果用户未登录,它具有将用户重定向到登录页面的机制。如果您未使用框架,则应检查用户的登录状态(可能在news1.php中)当他们单击上面的链接并重定向到登录页面(如果尚未登录)。

// in news1.php (if you are not using a framework )
header('Location: '.$newURL);

You are probably creating a session when a user logs in, make sure to check for the session in news1.php. 用户登录时可能正在创建会话,请确保在news1.php中检查该会话。 Something along these lines. 遵循这些原则。

//in news1.php 
if(!isset($_SESSION['myuserloginsession'])){
//$newUrl would be your login page
    header('Location: '.$newURL);
}

If isset $_SESSION goto this page? 如果isset $ _SESSION转到此页面?

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

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