在Codeigniter会话数据中保存URL

70gysomp  于 2022-12-07  发布在  其他
关注(0)|答案(4)|浏览(188)

我正在使用codigniter重定向用户后,他们已经登录到他们之前的网页。
示例URL可以是:
http://alpha.scrollr.co/app?tile=TITLE&credit=CREDIT&caption=CAPTION
下面是保存url的代码

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

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

并且在用户登录后使用该文件检索该文件:

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

然而,我无法检索实际的链接,我在URL中有多个GET参数。
有什么想法吗

a9wyjsp7

a9wyjsp71#

也许我太晚了,但也许有人需要它。你可以通过urlencode和decode。例如:

$url = 'https://example.com/';
      $this->session->set_userdata('url',urlencode($url));

而当你想取url.you时可以这样做:

$myurl = urldecode($_SESSION['url']);
      echo $myurl;

对于unset,就简单的这样:

unset($_SESSION['url']);
ojsjcaue

ojsjcaue2#

没有必要非常聪明,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
*/
?>
u0sqgete

u0sqgete3#

如何将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');
c86crjj0

c86crjj04#

如何将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');

相关问题