Forum Moderators: coopster
I think i need to use HTTP_REFERER but a little lost i did have a look at a previous post on this site, but couldn't make sense of it.
below is the basic code for the form and then for the php handeling page.
i think i'm going to need something on the homepage so that the URL can be grabbed and then passed to the form on the second page. like i said probably dead easy, but i'm loosing hair.
form page.....
<form method="post" action="http://www.example.com/_private/prospa/send-funnel1-NEW.php">
<input type="hidden" name="recd" value="<?=isset($recd) ? $recd : $HTTP_referer?>">
<div align="center">
<table width="508" border="1">
<tr valign="middle" class="style24">
<td width="105"><div align="left" class="style1">*Full Name:</div></td>
<td width="146" class="style1">
<input type="text" name="name">
</td>
<td width="71"><div align="left" class="style1">*Email:</div></td>
<td width="158" class="style1">
<input type="text" name="email">
</td>
</tr>
<tr valign="middle" class="style24">
<td><div align="left" class="style1">*Main Phone:</div></td>
<td class="style1">
<input type="text" name="homephone">
</td>
<td><div align="left" class="style1">2nd Phone or Mobile :</div></td>
<td class="style1">
<input type="text" name="mobile">
</td>
</tr>
<tr valign="middle" class="style24">
<td><div align="left" class="style17">*House Number or name </div></td>
<td><input name="housenumber" type="text"></td>
<td><div align="left" class="style17">Street</div></td>
<td><input name="street" type="text"></td>
</tr>
<tr valign="middle" class="style24">
<td><div align="left" class="style17">Town</div></td>
<td><input name="town" type="text"></td>
<td><div align="left" class="style17">City</div></td>
<td><input name="city" type="text"></td>
</tr>
<tr valign="middle" class="style24">
<td><div align="left" class="style17">County</div></td>
<td><input name="county" type="text"></td>
<td><div align="left" class="style17">*Postcode</div></td>
<td><input name="postcode" type="text"></td>
</tr>
<tr valign="middle" class="style24">
<td colspan="2"><div align="left" class="style17">Where did you hear about the Opportunity?
</div></td>
<td colspan="2">
<div align="left">
<span class="style17">
*
<select name="reflist" id="reflist">
<option>Please Select</option>
<option>Internet Search Engine</option>
<option>Personal recomendation</option>
<option>Email Invitation</option>
<option>Shop Ad, Card or Flyer</option>
</select>
</span>
<label><input onfocus="this.value = ''; this.onfocus = function () {}" type="text" name="referal" value="Distributor Name or 6 Digit Number" size="35"></label>
</div></td>
</tr>
</table>
<span class="style36">All fields marked * are required </span><br>
<p align="center" class="style17"> <input name="submit" type="submit" value=" Next > ">
</p>
<p class="style36">Applicants must be over eighteen and living in the UK, ROI, Germany or Netherlands. </p>
</div>
</form> </td>
</tr>
PHP HANDLER PAGE.....
<?php
$to = "jerrye@example.com" . ', ';
$to .= "shane@example.net";
$site = $_POST['recd'];
$name = $_POST['name'];
$email = $_POST['email'];
$homephone = $_POST['homephone'];
$mobile= $_POST['mobile'];
$housenumber= $_POST['housenumber'];
$street= $_POST['street'];
$town= $_POST['town'];
$city = $_POST['city'];
$county= $_POST['county'];
$postcode = $_POST['postcode'];
$reflist= $_POST['reflist'];
$referal = $_POST['referal'];
$d = date('l dS \of F Y h:i:s A');
$sub = "PROSpA Reply Form";
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers = "From: $name <$email>\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$mes .= "Site: ".$recd."\n<br>";
$mes .= "Name: ".$name."\n<br>";
$mes .= "House: ".$housenumber."\n<br>";
$mes .= "Street: ".$street."\n<br>";
$mes .= "Town: ".$town."\n<br>";
$mes .= "City: ".$city."\n<br>";
$mes .= "Postcode: ".$postcode."\n<br>";
$mes .= "Home Phone: ".$homephone."\n<br>";
$mes .= "Mobile: ".$mobile."\n<br>";
$mes .= "Email: ".$email."\n<br>";
$mes .= "Referal: ".$reflist."\n<br>";
$mes .= "Referal: ".$referal."\n<br>";
$mes .= "Date & Time: ".$d;
if (empty($name) ¦¦ empty($housenumber) ¦¦ empty($homephone) ¦¦ empty($postcode) ¦¦ empty($reflist))
{
echo " <h3>Sorry all fields marked * are required.</h3>";
}
elseif(!ereg("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)) {
print " <h3>Sorry the email address you entered looks like it's invalid.</h3>";
}
else
{
mail($to, $sub, $mes, $headers);
echo '<script language="Javascript">';
echo 'window.location="movie.htm"';
echo '</script>';
}
?>
hope this makes sense.
Jerry
[edited by: eelixduppy at 12:47 pm (utc) on Aug. 8, 2008]
[edit reason] exemplified [/edit]
<input type="hidden" name="recd" value="<?=isset($recd) ? $recd : $HTTP_referer?>">
Here is where your problem lies, then. I'm guessing you have the register_globals directive set in your configuration file? If you don't, ti doesn't really matter, but try the following instead:
<input type="hidden" name="recd" value="<?php echo isset($recd) ? $recd : $_SERVER['HTTP_REFERER']; ?>">
The code above doesn't assume any of your settings, and should pretty much work with anything. Try that and see if it helps.
entry.HTM -> formentry.HTM -> formhandler.PHP
entry.HTM
homepage, this is the one where i need to harvest the referer.
formentry.HTM
form entry for contact details along with a hidden field for the referer from entry.HTM
formhandler.PHP
sends the form via email including the hidden referer field.
hope this is making sense.
can you use php in your htm pages?
if not then you have a couple options
you could grab the referer and save it to a cookie using javascript. You would need to test to see if the cookie was already set, if it is, then don't save over it. Then grab the value from that cookie on your form page.
otherwise you could enable php parsing for the .htm extension and do as above using php, the only difference is with php you could use cookies or sessions, your choice.
the steps are pretty simple
check to see if cookie exists
if it does not exist then grab the referer and store it in a cookie
on you form page just grab the data from the cookie and put it in your form as a hidden element
on my index page i have...
<?php
$value = $_SERVER['HTTP_REFERER'];
setcookie("refercookie", $value, time()+360);
?>
and its coming through on the email. i'm trying to then delete the cookie with...
setcookie ("refercookie", "", time() - 360);
is that right?
just testing but not certain its there yet.
thanks again for all your help on this.
I would suggest a test to see if the cookie exists before you set it
<?php
if (!isset($_COOKIE['refercookie'])) {
$value = $_SERVER['HTTP_REFERER'];
setcookie("refercookie", $value, time()+360);
}
?>
i'm using..
setcookie ("refercookie", "", time() - 360);
to delete the cookie, i have this placed after the email is sent but before the page opens the next page (automated) i take it this is the right place. as i don't want to delete the cookie before i send it, but want rid asap.
makes sense?
Thanks again,
Jerry.
Many thanks,
Jerry
The other problem could be that the HTTP_REFERER is not always set. As this is something that is set by the client; therefore you have no control over it. So I would look for an implementation that does not require the referer and treat that piece of information as nice if you get it and ignore it if you dont.
If that is not an option then you may have to look at passing variables between the sites. If you are going to do this then just be aware that if you are going to get someone to link to a page using page.php?referer=example.com then it doesnt take a rocket scientist to work out how to get around your system. Hidden post variables have the same problem, as people can see them in the source code.