tags:

views:

45

answers:

5

I'm trying to use the page URL as a variable inside a form submission so that I can write it into my database and figure out what pages are getting more list sign-ups. Is there any easy way to do this?

+2  A: 

$_SERVER["REQUEST_URI"]

Ignacio Vazquez-Abrams
+1  A: 
<input type="hidden" name="page_url" id="page_url"/>
<script type="text/javascript">
document.getElementById("page_url").value = location.href;
</script>
Lucho
No referers for people with no javascript capabilities? Well, we're not on 2000, but that's an accessibility flaw, isn't it?
xPheRe
$_SERVER["HTTP_REFERER"] might not work always and yes - we are not 1999 anymore
Lucho
+1  A: 

Put the value of $_SERVER["REQUEST_URI"] inside a hidden input in the origin form, so you can check for it on the form processing script.

xPheRe
This will not work when the user goes on inpage anchor - then a #anchor will be added to the url and the form wont acknowledge it.
Lucho
Anchors are used only in the browser, never in the server, so the anchor will not be shown.
xPheRe
+1  A: 
$url = $_SERVER['HTTP_HOST'] . $_SERVER["REQUEST_URI"];
burntblark
A: 

Ideally, if every form links to the same parsing page, you have two options

Option 1: Created a hidden form variable on EVERY form page that records the URL of the page via static input, or from Javascript or PHP, both of which are detailed in the earlier answers.

Option 2: On the parsing page, use $url = $_SERVER['HTTP_HOST'] . $_SERVER["REQUEST_URI"] to get the page that directed to your parsing page, and record that in the database.

I would probably go with Option 2, as it is a bit more elegant and easier to modify, and can even let you know if a user attempted to inject the form with a copy they stored locally on their hard drive.

shmeeps