[英]Check if user is redirected from another page
I have a <form>
that sends the user to an external page: action="http:/example.com/test/test.php"
. 我有一个
<form>
,它将用户发送到外部页面: action="http:/example.com/test/test.php"
。 The test.php
on the external page executes an SQL query and sends the user to my internal page test2.php
. 外部页面上的
test.php
执行SQL查询,并将用户发送到我的内部页面test2.php
。 The second page test2.php
also executes an SQL query and the process gets closed. 第二页
test2.php
也执行SQL查询,并且过程关闭。
I want to perform an check operation in test2.php
. 我想在
test2.php
执行检查操作。 I only want to run the SQL query if the user is redirected from the external page. 如果用户是从外部页面重定向的,我只想运行SQL查询。
How can I do this? 我怎样才能做到这一点?
You can check the Referer
header with $_SERVER['HTTP_REFERER']
to see what page they were redirected from. 您可以使用
$_SERVER['HTTP_REFERER']
检查Referer
标头,以查看它们从哪个页面重定向。 This isn't reliable, though, since people can forge headers, but for the most part, if people are using browsers, you can use this to check if they were redirected. 但是,这并不可靠,因为人们可以伪造标题,但是在大多数情况下,如果人们正在使用浏览器,则可以使用它来检查它们是否已重定向。
为什么不使用像http://example.com/test/test.php这样的URL参数? redirect = true
Instead of having your form use a cross-domain action
, perhaps you can have your PHP code use curl to submit the information to the foreign server. 与其让您的表单使用跨域
action
,不如让您的PHP代码使用curl将信息提交到外部服务器。 Then your PHP code will know exactly what happened. 然后,您的PHP代码将确切知道发生了什么。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.