views:

452

answers:

3

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?

A: 

If the referring page is under your control, you could set a cookie on each page of your site, equal to the title.

Then on the Thank You page, you could read the cookie provided by the HTTP request, and insert that into the 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. Your database could then hold the title of the last page for each 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.

Oddthinking
+2  A: 

Put a hidden type input in your form, with page title as value. Then use the submitted hidden value.

Imran
+2  A: 

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.

Then in your link:

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