簡體   English   中英

代碼點火器-將URL放入URL參數

[英]Code Igniter - Put a URL into URL parameter

在Code Igniter中,我正在使用內置的URL類

我在這里有問題。 我想在當前URL中包含引薦來源網址。

例如,localhost / from_referrer / /account/verify/email/b4a98ddd44

/account/verify/email/b4a98ddd44是我要包含在當前URL中的URL。

我已經嘗試過urlencode()。 看起來像這樣

/account/login/from/%2Faccount%2Fverify%2Femail%2Fb4a98ddd44

但這不起作用。 CI認為我想去

/account/login/from//account/verify/email/b4a98ddd44

但我想去

/ account / login / from / /account/verify/email/b4a98ddd44 (突出顯示的只是參數)

你們每個人都知道如何制作嗎?

這只是一個想法

嘗試更換/-為您引用網址一樣

$referrer= str_replace('/', '-', '/account/verify/email/b4a98ddd44');

這樣您的網址就會變成這樣

account/login/from/-account-verify-email-b4a98ddd44

現在,在您的account controller's登錄功能中,如下所示

function login(){
$referrer= str_replace('-','/',$this->uri->segment(4));
}

現在,您可以通過多種方式執行此操作,例如您可以對URL進行哈希處理並在URL中附加,但是如果在URL中附加/account/verify/email/b4a98ddd44 ,CI會將其視為單個參數,例如

account => is the uri segment(4);
verify=> is the uri segment(5);
email=> is the uri segment(6);
b4a98ddd44=> is the uri segment(7);

因此,您需要制作一個不帶/的字符串,這樣它將在一個uri段中出現

希望有道理

如果您的網址始終以相同的段開頭,則可以嘗試獲取數組中的所有段,並在不需要的開頭刪除段。

$segs = $this->uri->segment_array();
unset ($segs[0]); //unset /account
unset ($segs[1]); //unset /login
unset ($segs[2]); //unset /from

$uri = implode('/', $segs);
echo $uri; // echoes "account/verify/email/b4a98ddd44"

另一個可能的解決方案:這不是您的問題的旁聽者,而是(更好的)解決方法。

為什么不將HTTP Referer與Codeigniter Flash數據結合使用? 當用戶進入登錄頁面時,在控制器中設置閃存數據

$this->session->set_flashdata("referer",$_SERVER['HTTP_REFERER']);

然后在用戶登錄后,您可以使用它再次檢索值

$uri = $this->session->flashdata("referer");

閃存數據點火器手冊

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM