2015-04-29 65 views
0

在我的网站我有一个机制,当你的会话已经过期我保存当前位置并将你重定向到登录页面登录,所以URL如下获取URL,包括通过URL传递的参数作为参数

localhost/mytest/admin/login-admin.html?current=localhost/mytest/admin/manage-customer.php?action=update&id_annonceur=2

一旦您登录,我将用户重定向到存储在当前参数中的url。 问题是,当我使用下面的代码

if(isset($_GET['current'])) 
    header('Location: http://'.$_GET['current']); 
else 
    header('Location: ../admin/dashboard.php'); 

我得到无参数的URL包含在URL

http://localhost/mytest/admin/gestion-annonceur.php?action 

有没有一种方法来检索完整的URL包括参数?

+1

当您设置'$ _GET ['current']' –

+0

时,使用'urlencode'和'urldecode'您的URL无效。你不应该有两个查询字符串(即两个'?')。您需要使用['http_build_query()'](https://php.net/http_build_query)或其他适当的方法将它传递到登录页面之前对url进行编码... – War10ck

回答

3

确保在将URL放入current参数中时对原始URL进行URL编码。它应该是:

localhost/mytest/admin/login-admin.html?current=localhost%2Fmytest%2Fadmin%2Fmanage-customer.php%3Faction%3Dupdate%26id_annonceur%3D2 

使用urlencode() PHP函数生成此编码。