php 中的引用-
执行以下操作的最佳方法是什么: 我的页面 A 有 2 个按钮(用于不同的事情),它们都会带您进入登录页面(第 3 页),当第 3 页填写登录详细信息时,处理数据的页面是第 4 页。 我希望第 4 页根据在第 a 页中单击的按钮来显示内容。我已经阅读了httpreferer,但我相信如果我在第4页中放置一个referer,它将显示我来自的上一页,即登录页面。
我该如何解决这个问题? 谢谢
What is the best method of doing the following:
I have Page A with 2 buttons(for different things) which both take you to a login page(Page 3), When login details are filled in Page 3, the page that handles the data is page 4.
I want page 4 to show things depending on which button was clicked in page a. I have read upon http referer, but i believe if i place a referer in Page 4, it will show the previous page that i am coming from, which is the login.
How can i resolve this?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
引用者并不总是由浏览器发送,并且可以被伪造(在这种情况下,由于两个按钮都在同一页面上,因此它有点无用);因此,您不应依赖它的设置或正确性。
在这种情况下,一个可能的解决方案是:
page_login.php?button=1
”page_login.php?button=2
”$_GET['button']
),并将其存储在表单的隐藏字段中,The referer is not always sent by browsers, and can be faked (and, in this case, as both buttons are on the same page, it would be kind of useless) ; so, you should not depend on it being set nor correct.
In this situation, a possible solution would be to :
page_login.php?button=1
"page_login.php?button=2
"$_GET['button']
), and store it in a hidden field of the form使用会话变量,例如
$_SESSION['clicked_button'] = $the_button
。Use a session variable, eg
$_SESSION['clicked_button'] = $the_button
.http-referer 不是执行此操作的最佳解决方案。最简单的方法是向 GET 数组添加一些参数,例如
?clicked_button=2
HTTP-referer 可能已关闭。此外,Referer 将显示该按钮的相同 url(它们都在一页中)
根据请求进行编辑:
没有形式你也可以做到,
并在
page3.php
中读取值在$_GET['clicked_button']
中:if($_GET['clicked_button'] == 1) ...
http-refferer is not the best solution to do this. Simplest way is add some parametr to GET array, for example
?clicked_button=2
Http-refferer could be off. Moreover, referer will be display same url for that buttons (both of them are in ONE page)
EDIT on request:
You could do it without form,
<button id="button1" onClick = "javascript:location = "page3.php?clicked_button=1"; />
and in
page3.php
just read value in$_GET['clicked_button']
:if($_GET['clicked_button'] == 1) ...
如果这些变量不存在,请记住在任何情况下都有一个默认值,即用户干扰您的表单......但无论如何您应该使用方法来防止这种情况;)
Remember to have a default in any case if those variables do not exist, ie user interferes with your form... but you should be using methods to prevent that anyways ;)