简体   繁体   English

登录后执行功能并重定向到上一页

[英]After Login Execute A Function And Redirect To Previous Page

I've created a page like all_elements , which contains list of elements and provided an option to adding an element to wishlist . 我创建了一个类似于all_elements的页面,其中包含list of elements并提供了adding an element to wishlist的选项。

The steps are as follows. 步骤如下。

  1. If the user is logged in, the element is adding to wishlist through an ajax call . 如果用户已登录,则该元素通过ajax call添加到愿望清单。
  2. If the user is not logged in, it has to ask an user to login. 如果用户未登录,则必须要求用户登录。
  3. After the login is success, the element has to added to wishlist and redirect to all_elements page . 登录成功后,该元素必须added to wishlist并重定向到all_elements page

I'm trying following steps. 我正在尝试执行以下步骤。

  1. If the user is not logged in, saving the link for adding an element to wishlist and redirecting to login page. 如果用户未登录,请保存用于将元素添加到愿望清单并重定向到登录页面的链接。
  2. After login success, its redirecting to all_elements page . 登录成功后,其重定向到all_elements page But I'm checking every time the session link which included adding course to wishlist . 但是我每次都在检查session link which included adding course to wishlist

But I'm thinking this is bad coding because every time I need to check the session link in all_elements page . 但我认为这是不好的编码,因为每次我需要检查all_elements page的会话链接时,都all_elements page

Please suggest me good solution and the work would be appreciated. 请建议我一个好的解决方案,我们将不胜感激。

If I understood correctly, This is done with a GET paramter to the login page( as POST paramter if the form is ajaxy). 如果我正确理解,可以使用登录页面的GET参数(如果表单为ajaxy,则为POST参数)来完成此操作。

For example, Assume I want to click somewhere that requires login, That links i called www.example.com/secret. 例如,假设我要单击需要登录的位置,该链接称为www.example.com/secret。

You can store the URI segment (or the whole URL) as $_GET param, as soon as you login your function check if $_GET['redirect'] exists, if it does, try to redirect to it. 您可以将URI段(或整个URL)存储为$ _GET参数,一旦登录函数,请检查$ _GET ['redirect']是否存在,如果存在,请尝试将其重定向。

This way the 'redirect' logic is embeded in the login itself, and not in any other functionality, this allows you to extend this functionality to any other part of the website, instead of checking the session. 这样,“重定向”逻辑被嵌入到登录本身中,而不嵌入任何其他功能中,这使您可以将此功能扩展到网站的任何其他部分,而不用检查会话。

This can also be done using the session, storing the link in a $_SESSION['redirect'] variable. 也可以使用会话来完成,将链接存储在$ _SESSION ['redirect']变量中。 In anyway, These checks should be done after login, and not in any single page 无论如何,这些检查应在登录后进行,而不要在任何页面中进行

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

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