Forum Moderators: coopster
<input name="referer" type="hidden" value="<?php echo $referer;>"/>
// Set to actual referer initially (default)
$referer = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : null;
// When form is submitted, grab referer from form
$referer = isset($_POST['referer']) ? $_POST['referer'] : $referer;
You said: unless you include this in the URL? (Although you would also have trouble hanging on to all your other form data as well.)
Can it give me problems? ...
[edited by: helenp at 10:48 am (utc) on Aug 22, 2011]
$_SERVER['SCRIPT_NAME']which holds the root-relative path to the current script (ie. the current page / contact page). An alternative to using $_SERVER['PHP_SELF'], but safer.
This I am using and works;
action="<?php echo $_SERVER['contact.htm']; ?>"
It gives action="" when I check the code in the browser.
action=""which does indeed work. All browsers submit the form back to the current page when the action attribute is empty. I believe this is universal among browsers - so it works. However, it is not strictly part of the HTML 4.01 spec which states that behaviour is undefined if a valid URI is not provided. However, it is due to be part of the HTML 5 spec! So, regardless of the spec, it works and AFAIK it is safe.
action="<?php echo $_SERVER['SCRIPT_NAME'];?>"
and the broswer gives when checking code:
action="/contact.htm"
action=""