Referrer url not working

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
kaYak
Forum Commoner
Posts: 65
Joined: Mon Feb 02, 2004 2:43 pm
Location: USA

Referrer url not working

Post by kaYak »

This is my 404 page for my site. I want to be able to send myself some information. The email is sent fine but I want to include the referrer page. So like if a user came to the 404 page from a_page.php then it would tell me "a_page.php". The code below is the code I have so far. I also wanted it to be able to output either a read only input box or a text based on whether or not the refferer page variable is blank or not. If it is blank then I want it to let the user enter something. If it is not blank then I just want it to tell the user the referrer page. Can someone please help me? If you have any questions about what I'm trying to do here feel free to reply here or contact me. Thanks.

Code: Select all

<?php

if(isset($mailform)) &#123;
	mail("MYEMAIL", "404 Error", "Comment: $comment \n\n URL 1: $refer \n\n URL 2: $refer2 \n\n IP: $REMOTE_ADDR \n\n Browser: $HTTP_USER_AGENT \n\n", "From: form");
	echo "<BR><BR><BR>Thank you.";
	&#125;
	else &#123;
		echo "<center><BR><BR><BR></center><p>Please fill out the form here if you got here by a link.
		<form method=POST action='404error.php'>
		<table>
		<tr><td>URL with link:</td><td>"; 
		if($HTTP_REFERER="")&#123;echo "<input type='text' value='' name='refer2'>";&#125; 
		else&#123;echo "<input type='hidden' name='refer' value='$HTTP_REFERER' >$refer";&#125; echo "</td></tr>
		<tr><td>Comment:</td><td><textarea rows=4 cols=24 name='comment' maxlength=400></textarea></td></tr>
		<input type='hidden' name='mailform' value='iamset'>
		<tr><td></td><td><input type='submit' value='Submit'></td></tr></table>
		&#125;

?>
User avatar
DuFF
Forum Contributor
Posts: 495
Joined: Tue Jun 24, 2003 7:49 pm
Location: USA

Post by DuFF »

Take a look at this line:

Code: Select all

<?php
if($HTTP_REFERER=""){echo "<input type='text' value='' name='refer2'>";}
?>
The "=" operator sign means, set $HTTP_REFERER equal to nothing. You want to use the "==" operator sign, which checks to see if $HTTP_REFERER is equal to nothing. The best way would probably be:

Code: Select all

<?php
if(empty($HTTP_REFERER)){echo "<input type='text' value='' name='refer2'>";}
else{echo "<input type='text' name='refer' value='$HTTP_REFERER' readonly='readonly'>";}
?>
If HTTP_REFERER is set, the form input will be read only.
kaYak
Forum Commoner
Posts: 65
Joined: Mon Feb 02, 2004 2:43 pm
Location: USA

Post by kaYak »

Thanks a lot!
Post Reply