简体   繁体   English

基本的PHP表单帮助 - referer标题

[英]Basic php form help - referer title

I now have it set up so that when people go to a "thank you" page after filling out a form, they go to a page that says: 我现在已经设置好了,当人们在填写表格后转到“谢谢”页面时,他们会转到一个页面,上面写着:

   thanks for coming <a href="<?php echo $_SERVER['HTTP_REFERER'] ?>here's a link back to where you came from</a>

What I want is for it to say: 我想要的是它说:

   thanks for coming <a href="<?php echo $_SERVER['HTTP_REFERER'] ?>here's a link back to <?php echo TITLE OF REFERRING PAGE ?></a>

Is there a simple way to do this? 有一个简单的方法吗?

Put a hidden type input in your form, with page title as value. 在表单中放入一个隐藏的类型输入,页面标题为值。 Then use the submitted hidden value. 然后使用提交的隐藏值。

The simplest way is to pass the page title as a session variable: 最简单的方法是将页面标题作为会话变量传递:

<?php

  $_Session["referrerTitle"] = $pageTitle;

 ?>

If you are working with a Header file include, you may have this variable set already in the referring page. 如果您正在使用Header文件include,则可能已在引用页面中设置了此变量。

Then in your link: 然后在你的链接中:

<p>   thanks for coming <a href="<?= $_SERVER['HTTP_REFERER']"?>here's a link back to <?= $_Session["referrerTitle"] ?></a></p>

If the referring page is under your control, you could set a cookie on each page of your site, equal to the title. 如果引荐页面在您的控制之下,您可以在网站的每个页面上设置一个cookie,等于标题。

Then on the Thank You page, you could read the cookie provided by the HTTP request, and insert that into the HTML. 然后在Thank You页面上,您可以读取HTTP请求提供的cookie,并将其插入HTML。

Similarly, you could track session information, so the cookie doesn't actually hold the title, but instead hold a unique id for each visitor. 同样,您可以跟踪会话信息,因此cookie实际上并不包含标题,而是为每个访问者保留一个唯一的ID。 Your database could then hold the title of the last page for each id. 然后,您的数据库可以保存每个ID的最后一页的标题。 This is a bit of overkill, for what you asked, but if you need to track session data anyway, it might be cleaner. 对于你提出的问题,这有点过分,但如果你需要跟踪会话数据,它可能会更清晰。

Both solutions rely of the user's browser supporting cookies. 这两种解决方案都依赖于用户的浏览器支持cookie。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM