2014-03-25 82 views
-1

我正在使用codigniter在用戶登錄到之前的頁面後重定向用戶。將URL保存在Codeigniter會話數據中

一個例子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'); 

但是我無法檢索actual_link我有更多的e在URL中獲取參數。

任何想法

+0

你的意思是你想用戶重定向到前一頁後,他們登錄或別的東西 –

+0

更新它惋惜:我的意思是我無法訪問$ actual_link –

回答

0

如何將獲取變量存儲到會話中。

像這樣:

$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'); 
+0

是否得到current_url保持我得到參數 –

+0

正如我從URL Helper中學到的。 current_url() - 獲取整個URL。你至少應該諮詢CodeIgniter的URL HELPER,它很安靜(http://ellislab.com/codeigniter/user-guide/helpers/url_helper.html) – YouSer

+0

它只返回http://alpha.scrollr.co/app –

0

如何存儲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'); 
0

有沒有必要非常聰明。 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 
*/ 
?> 
相關問題