p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


  Return to Index  

beginning_php thread: Passing a URL to a form


Message #1 by "Lonnie Minter" <lminter@f...> on Wed, 12 Feb 2003 11:28:43 -0600
I would like to record what page a person was on when they clicked on a
link that takes them to a form.
 
 

Message #2 by "Nikolai Devereaux" <yomama@u...> on Wed, 12 Feb 2003 11:23:04 -0800
> I would like to record what page a person was on when they clicked on a
> link that takes them to a form.


Well, their browser might send the http referer, which you can check in PHP
via $_SERVER['HTTP_REFERER'].

Since you can't depend on this, you can modify your site to include the page
id of any page that links to your form.

For example, suppose you had three pages, page1.php, page2.php, and form.php


page1.php outputs this link:

<a href="form.php?from=page1.php">Go to the form</a>

and page2.php outputs this link:

<a href="form.php?from=page2.php">Go to the form</a>



Within form.php, you can check the existence of $_GET['from'] to see if the
user accessed the form from within your site and from which page.


hth,

Nik

Message #3 by "Nikolai Devereaux" <yomama@u...> on Wed, 12 Feb 2003 13:38:50 -0800
Lonnie -- one more suggestion.

It might be easier to *not* pass the URL of the previously accessed page to
the form, but to maintain the most recently accessed page in a session
variable, and check that variable in the form page.

That is, every page in your site can include something like this line:

$_SESSION['mrp'] = $_SERVER['PHP_SELF'];


(Don't forget session_start()!)


In the form page, check:

if(isset($_SESSION['mrp']))
{
   // user came from within your site.
}
else if(isset($_SERVER['HTTP_REFERER']))
{
   // user came from somewhere else
}
// user did not come from your site, nor does their browser
// send http referer information.



hth,

Nik


  Return to Index