简体   繁体   中英

PHP URL Redirecting

I am working on a site that allows system user login. And I face some scenario below:

If let say User A clicked on an email link ( https://www.example.com/user/1 ), User A will be redirected to the login page if haven't login or User A will be redirected to the email clicked URL if User A already logged in. The question here is that how to redirect User A to the email clicked URL right after login successful instead of https://www.example.com/home by default.

Correct me if I'm wrong.

There are 2 approaches to achieve it:

I see many (big) websites are doing that, just send a GET info to the www.example.com/home, let's say will look like that: www.example.com/home?redirect=email , you can send how many variables you want, you can also use hash to make it more secure and less readable for the user, you can choose this approach if you don't want to create a SESSION for the user for this tiny issue. 我看到许多(大型)网站都在这样做,只需将GET信息发送到www.example.com/home,就可以像这样: www.example.com/home?redirect=email ,您可以发送所需的变量数量,也可以使用哈希使其对用户更安全和更易读,如果您不想为此用户创建SESSION,则可以选择此方法小问题。

if the user is not logged in, create a SESSION with the desired location to redirect, then get that SESSION variable in the /home through $_SESSION or through other methods (if you use a framework such as Laravel). 如果用户未登录,请创建具有所需重定向位置的SESSION,然后通过$_SESSION或通过其他方法在/home获得该SESSION变量(如果使用诸如Laravel)。

I suggest go with approach 1, it is very common. The reason I think it is better than approach 2 is because that this task is not what Sessions are for.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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