Forum Moderators: coopster

Message Too Old, No Replies

Need to see where visitors came from

When they submit a contact form

         

casey133

6:11 am on Jan 3, 2007 (gmt 0)

10+ Year Member



Hi,

I hope someone can help me with this issue as I've search and cannot find an answer.

I have a basic contact form that works fine, what I need to add is the ability to see what website the visitors came from. Here is the form code as of now:

<form name="form2" method="post" action="contact.php">
<table width="100%" border="0" cellspacing="1" cellpadding="3">
<tr>
<td width="50%"><div align="left"><strong>Name <br>
<input name="Name" type="text" class="form" id="Name">
<br>
Email <br>
<input name="Email" type="text" class="form" id="Email">
<br>
Phone<br>
<input name="Phone" type="text" class="form" id="Phone">
<br>
Comments</strong><br>
<textarea name="Comments" cols="50" rows="5" class="textarea" id="Comments"></textarea>
<br>
<input name="Reset" type="reset" class="submit" value="Reset">
<input name="Submit2" type="submit" class="submit" value="Submit">
<br>
<br>
</div>
</td>
</tr>
</table>
<br>
<br>
<span style="margin-left:8px; width:147px "><strong>114 Front Street <br>
City, ST 12345 <br>
Tel./Fax number deleted<br>
<a href="mailto:email@domain.com">email@domain.com</a></strong></span>
</form>

Thanks for any help with this!

mcibor

12:43 pm on Jan 3, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It could be

$_SERVER['HTTP_REFERER']

you are looking for.

For more info see
[php.net...]

but remember, that this variable isn't always acurate, cause many browsers don't send that information.

Regards
Michal Cibor

whoisgregg

6:26 pm on Jan 3, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If you are using sessions, you can keep an updated list of the most recently visited pages. This could be used for a number of very helpful interface features and can be included in the posting of any contact form.

You could add something along the lines of this untested pseudocode in your global include file:

$_SESSION['last_five_pages'][] = $_SERVER['REQUEST_URI'];
if(count($_SESSION['last_five_pages']) > 5){
// prune the oldest entry
$oldest_entry = array_shift($_SESSION['last_five_pages']);
}

[edited by: whoisgregg - Wed, 03 Jan 2007 18:50:25 GMT] Whoops, messed up a big detail, should be better now but it's still untested code and needs improvement.