PHP在Google应用程序引擎中,如何检测传入重定向的url?
我不确定这是否可行,但想知道我们是否可以从PHP在Google应用程序引擎中,如何检测传入重定向的url?,php,google-app-engine,url,url-redirection,Php,Google App Engine,Url,Url Redirection,我不确定这是否可行,但想知道我们是否可以从标题('Location:')开始的位置检测url 我有两个带有标题('Location:/main.php')的脚本,现在当执行main.php时,我想知道重定向是从哪个脚本或URL启动的 script.php header('Location: /main.php'); main.php //detect the source url.. ie /script.php or website.com/script.php // do some act
标题('Location:')
开始的位置检测url
我有两个带有标题('Location:/main.php')
的脚本,现在当执行main.php时,我想知道重定向是从哪个脚本或URL启动的
script.php
header('Location: /main.php');
main.php
//detect the source url.. ie /script.php or website.com/script.php
// do some action
header('location: /script.php');
这可能吗?我想你可以在main.php上使用类似的东西
$referer = $_SERVER["HTTP_REFERER"];
我想你可以在main.php上使用类似的东西
$referer = $_SERVER["HTTP_REFERER"];
我用下面的代码让它为我工作
script.php
$document = $_SERVER['REQUEST_URI'];
$host = $_SERVER['HTTP_HOST'];
$fullPath = $host.$document;
setcookie('referer', $fullPath,time()+86400); // cookie is destroyed on redirect
header('Location: /main.php?referer='.$fullPath);
另一个如下所示
main.php
$referer = $_REQUEST['referer'];
if($referer != null){
header("location: http://".urldecode($referer));
}
我设置的cookie在执行main.php
时被删除,因此我必须通过POST发送信息。
我还必须在$referer上使用urldecode
这可能不是最好的方法,但它确实有效,如果有人能改进它,我很乐意从中学习。我用下面的代码让它为我工作
script.php
$document = $_SERVER['REQUEST_URI'];
$host = $_SERVER['HTTP_HOST'];
$fullPath = $host.$document;
setcookie('referer', $fullPath,time()+86400); // cookie is destroyed on redirect
header('Location: /main.php?referer='.$fullPath);
另一个如下所示
main.php
$referer = $_REQUEST['referer'];
if($referer != null){
header("location: http://".urldecode($referer));
}
我设置的cookie在执行main.php
时被删除,因此我必须通过POST发送信息。
我还必须在$referer上使用urldecode
这可能不是最好的方法,但它确实有效,如果有人能改进这一点,我很乐意从中学习。我认为它应该在正常的服务器上工作。但我一直在犯这个错误<代码>注意:未定义索引:HTTP\u REFERER这似乎很奇怪。我想知道在google app engine中运行该网站是否有不同之处。该错误通常发生在HTTP_REFERER为null时。。您可以使用
if(isset($var))
或if($var null)
这样的代码,其中var是$\u服务器[“HTT\u REFERER”]
,但我不确定这是否仍然适用于您的场景。我假设它应该适用于普通服务器。但我一直在犯这个错误<代码>注意:未定义索引:HTTP\u REFERER这似乎很奇怪。我想知道在google app engine中运行该网站是否有不同之处。该错误通常发生在HTTP_REFERER为null时。。您可以使用if(isset($var))
或if($var null)
这样的代码,其中var是$\u服务器[“HTT\u REFERER”]
,但我不确定这在您的场景中是否仍然有效。