douqiang1851 2017-04-24 14:36
浏览 10
已采纳

登录然后重定向到引用链接

The app I'm working on has a vacation module. Employee X registers a request for a vacation and his manager receives an email saying that X wants a vacation. Until now, the manager had to login and then navigate to the vacation section and approve or reject the request, but I added buttons in the email to directly approve or reject the request. The only problem I have is that I do not know how to redirect the manager to the link in the email after the login. If he's already logged in, the app works great, but if he is not I need a way to store the link he got in the email and use it afterwards.

I have a User class where I hold all the information in the database about the logged user after the login and I tried to add a call to the uri_string() method there, but as User is an autoloaded library, it calls the method on every page refresh. So I tried to check using strpos() if I have a portion of the desired link in the URI and then store it, but for some reason the link from the email does not get stored.

So how to store the referring link if it is from an external source?

The app is developed in PHP, using the CodeIgniter framework.

EDIT: It didn't work because of several reasons:

  1. I was overthinking the problem.
  2. In the User library that I have I was overwriting over and over again the variable where I was supossed to store the link (it was one of the little things you miss when you are tired); So I always ended up with an empty string there.
  3. The guy who worked here before (the one that developed the app) had a very chaotic way of writing code
  4. I WAS WAY OVERTHINKING IT!

Thank you!

  • 写回答

1条回答 默认 最新

  • dsdeeaquu38538545 2017-04-24 15:13
    关注

    As Jon Stirling & Khan Shahrukh said in comments the simplest way is to store link in the session.

    Basically you should do changes in 2 places:

    1. In code that checks if user is authenticated something like this should be added:

      if ($notAuthenticated) { // checked somewhere before
          $session->set_userdata('redirect_after_login', base_url(uri_string()));  // session library was loaded somewhere above
      }
      
    2. And in code that actually auth users add this:

      // after success auth (and after all other code does their job)...
      $redirectAfterLogin = $session->userdata('redirect_after_login');  // session library was loaded somewhere above
      if ($redirectAfterLogin) {
          redirect($redirectAfterLogin);
      }
      
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 给自己本科IT专业毕业的妹m找个实习工作
  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
  • ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)
  • ¥50 mac mini外接显示器 画质字体模糊
  • ¥15 TLS1.2协议通信解密
  • ¥40 图书信息管理系统程序编写
  • ¥20 Qcustomplot缩小曲线形状问题
  • ¥15 企业资源规划ERP沙盘模拟
  • ¥15 树莓派控制机械臂传输命令报错,显示摄像头不存在
  • ¥15 前端echarts坐标轴问题