簡體   English   中英

登錄重定向的動態變量

[英]Dynamic variable for a login redirection

我最近在我的網站上實現了一個具有登錄/用戶系統的文件管理器(FileGator),但是在嘗試修改重定向代碼時遇到了一些麻煩。 我的登錄表單出現在每個頁面上,當前登錄的用戶會自動重定向到他正在瀏覽的頁面。

那里有一個特定的頁面,我希望將我的用戶重定向到其他地方,所以我想出了一個可以正常工作的代碼:

// reload
        if(isset($_REQUEST['redirect']) && ($_REQUEST['redirect'])!=='http://mywebsite.home/ftp/?login=1' )
            $url = $_REQUEST['redirect']; // holds url for last page visited.
        else {
            header('Location: '.gatorconf::get('base_url').'/?cd='); // default page 
            die;
        }
        header("Location:$url");
        die;

因此,使用該代碼,如果當前頁面的URL為http://mywebsite.home/ftp/?login=1 ,我的用戶將始終重定向到同一頁面,在這種情況下,他將被重定向到“默認頁面”(這也是用戶從文件管理器的登錄頁面登錄后重定向的狀態。

但是我想要的是URL http://mywebsite.home/ftp/?login=1像這樣是“動態的”: "base_url"/ftp/?login=1這樣它既可以在本地也可以在我上傳的所有地方,它看起來也更干凈。

我嘗試使用文件管理器的代碼行('Location: '.gatorconf::get('base_url').'/?cd=') ,這似乎會自動獲取我的基本URL。

我試過了

// reload
    if(isset($_REQUEST['redirect']) && ($_REQUEST['redirect'])!==(.gatorconf::get('base_url')./?login=1) )
        $url = $_REQUEST['redirect']; // holds url for last page visited.
    else {
        header('Location: '.gatorconf::get('base_url').'/?cd='); // default page 
        die;
    }
    header("Location:$url");
    die;
}

還嘗試了$ variable之類的東西:

// reload
        $default_redirect = .gatorconf::get('base_url').'/?login=1';
        if(isset($_REQUEST['redirect']) && ($_REQUEST['redirect'])!==($default_redirect) )
            $url = $_REQUEST['redirect']; // holds url for last page visited.
        else {
            header('Location: '.gatorconf::get('base_url').'/?cd='); // default page 
            die;
        }
        header("Location:$url");
        die;
    }

但是,由於現在可能很明顯,即使經過一些研究,我對php的了解也不多,也找不到正確的方法來放置它。 誰能幫我這個 ?

非常感謝

經過一番努力之后,我終於找到了解決我問題的正確代碼:

if(isset($_REQUEST['redirect']) && ($_REQUEST['redirect']!==gatorconf::get('base_url').'/?login=1'))

暫無
暫無

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

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