[英]Save URL in Codeigniter Session Data
在用戶登錄到他們之前所在的頁面后,我正在使用 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 參數。
有任何想法嗎
也許我為時已晚,但也許有人需要它。 您可以通過 urlencode 和解碼來完成。 例如:
$url = 'https://example.com/';
$this->session->set_userdata('url',urlencode($url));
當你想獲取 url.you 可以這樣:
$myurl = urldecode($_SESSION['url']);
echo $myurl;
對於未設置,就像這樣簡單:
unset($_SESSION['url']);
如何將獲取變量存儲到會話中。
像這樣:
$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
然后你可以在之后取消它們。
$this->session->unset_userdata('tile');
$this->session->unset_userdata('credit');
$this->session->unset_userdata('caption');
如何將獲取變量存儲到會話中?
像這樣:
$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
然后你可以在之后取消它們。
$this->session->unset_userdata('tile');
$this->session->unset_userdata('credit');
$this->session->unset_userdata('caption');
沒有必要非常聰明。 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
*/
?>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.