【问题标题】:Save URL in Codeigniter Session Data在 Codeigniter 会话数据中保存 URL
【发布时间】:2014-03-25 09:45:45
【问题描述】:

在用户登录到他们之前所在的页面后,我正在使用 codigniter 重定向用户。

一个示例网址可能是:

http://alpha.scrollr.co/app?tile=TITLE&credit=CREDIT&caption=CAPTION

这是保存网址的代码

$actual_link = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";

 $this->session->set_userdata('redirect', $actual_link);

这用于在他们登录后检索它:

$actual_link = $this->session->userdata('redirect');

但是我无法检索到 actual_link 我在 url 中有多个 GET 参数。

任何想法

【问题讨论】:

  • 你的意思是你想在用户登录或其他东西后将用户重定向回上一页
  • 已更新抱歉:我的意思是我无法访问 $actual_link

标签: php codeigniter session get


【解决方案1】:

没有必要非常聪明。 Codeigniter 已经非常聪明了;

就这样吧:

<?php
/**
 * set session variable 'redirect'
 * with URL and query string
 */
$this->session->set_userdata ( 'redirect', current_url () . '?'. $this->input->server ( 'QUERY_STRING' ) );

/**
 * get session variable 'redirect'
 * with URL and query <string></string>
 * and redirect to user
 */
redirect ( $this->session->userdata ( 'redirect' ) );

/*
If URL is: 
http://localhost/development/ci-admin-with-template/index.php?test=pass&user=valid
User will Redirect on: 
http://localhost/development/ci-admin-with-template/index.php?test=pass&user=valid

If URL is: 
http://localhost/development/ci-admin-with-template/?test=pass&user=valid
User will Redirect on: 
http://localhost/development/ci-admin-with-template/index.php?test=pass&user=valid
*/
?>

【讨论】:

    【解决方案2】:

    如何将 get 变量存储到会话中。

    像这样:

    $domain = current_url(); //http://alpha.scrollr.co/app
    $this->session->set_userdata('tile'   , 'TITLE'); //stores the title
    $this->session->set_userdata('credit' , 'CREDIT'); //stores the credit
    $this->session->set_userdata('caption', 'CAPTION'); //stores the caption
    

    然后你可以UNSET他们之后。

    $this->session->unset_userdata('tile');
    $this->session->unset_userdata('credit');
    $this->session->unset_userdata('caption');
    

    【讨论】:

    【解决方案3】:

    将get变量存储到会话中怎么样?

    像这样:

    $domain = current_url(); //http://alpha.scrollr.co/app
    $this->session->set_userdata('tile'   , 'TITLE'); //stores the title
    $this->session->set_userdata('credit' , 'CREDIT'); //stores the credit
    $this->session->set_userdata('caption', 'CAPTION'); //stores the caption
    

    然后你可以UNSET他们之后。

    $this->session->unset_userdata('tile');
    $this->session->unset_userdata('credit');
    $this->session->unset_userdata('caption');
    

    【讨论】:

      猜你喜欢
      • 2016-06-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-07-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多