Solved

Error Page 404

Posted on 2007-11-30
12
171 Views
Last Modified: 2010-04-06
Hi,

I have quite a large Web Site which is update all the time.  To correct any errors which may take place, i'm trying to include on my 404 error page the page the user was on when they were taken to the error page and what link they were trying to find, ann then allow the user to submit these details to the webmaster by clicking a button.

Can this be done and if so, can someone advise how to achieve it?

Kind Regards,
Anthony
0
Comment
Question by:d10u4v
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 6
12 Comments
 
LVL 21

Accepted Solution

by:
nizsmo earned 500 total points
ID: 20381246
You can use http_referrer in PHP to do this:

to try that this works:

<?php
echo $_SERVER['HTTP_REFERER'];
?>

Then you can on your custom 404 page, build a simple email form and auto fill the email form field with the referrer value, then allow the user/visitor to send this to the webmaster.

Hope this helps.
0
 

Author Comment

by:d10u4v
ID: 20381422
How do i autofill the form?  Do i just put ['HTTP_REFERER'] in the Init Val of the form field?

Anthony
0
 
LVL 21

Expert Comment

by:nizsmo
ID: 20381463
you can put it in an invisible field, which upon submitting the form will submit this field too:

// ...code...//
<input type="hidden" name="referer" value="<?php echo $_SERVER['HTTP_REFERER']; ?>">
// ...code...//
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:d10u4v
ID: 20381627
I have inserted:
<?php
echo $_SERVER['HTTP_REFERER'];
?>
Into one of my cells on my error page and have tested it on the server, and othing happens.  It dons't show the refered page...

Anthony
0
 
LVL 21

Expert Comment

by:nizsmo
ID: 20381648
This will show up as BLANK if you are not coming from anywhere and simply going to the script directly. To make it show something, create a hyperlink linking to the page with the code:
<?php
echo $_SERVER['HTTP_REFERER'];
?>

and you should see something.

hope this helps.
0
 

Author Comment

by:d10u4v
ID: 20381667
I tested it by uploading it and going to a link i know does not exits.

Anthony
0
 
LVL 21

Expert Comment

by:nizsmo
ID: 20381681
what is your code, are you able to post it?
0
 

Author Comment

by:d10u4v
ID: 20381768
This is my complete HTML code for the error page:


<html>
 
<head>
<title>ARchive Services Data & Records Management Ltd  ::  404 Page Not Found</title>
<link href="http://www.archiveservices.co.uk/Style/StyleSheet.css" rel="stylesheet" type="text/css">
<style type="text/css">
</style>
</head>
 
<body>
<center>
  <table width="50%" align="center" cellpadding="2" cellspacing="2">
    <tr>
      <td width="19%">&nbsp;</td>
      <td width="64%" class="Heading"><div align="center" class="style2">404</div></td>
      <td width="17%">&nbsp;</td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td><div align="center"><img src="http://www.archiveservices.co.uk/Images/Logo.gif" width="315" height="66"></div></td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td class="Heading"><div align="center">Page Not Found ! </div></td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td><div align="center" class="GeneralText"></div></td>
      <td><div align="center" class="Heading">
        <?php
echo $_SERVER['HTTP_REFERER'];
?>
      </div></td>
      <td><div align="center"></div></td>
    </tr>
    <tr>
      <td height="57">&nbsp;</td>
      <td class="GeneralText"><div align="justify"><span class="GeneralText"><font face="Verdana, Arial, Helvetica, sans-serif">You may have typed the web address incorrectly. Please check the address and   spelling ensuring that it does <strong>not</strong> contain</font></span><span class="style7"><font face="Verdana, Arial, Helvetica, sans-serif"> any </font></span><span class="GeneralText"><font face="Verdana, Arial, Helvetica, sans-serif">spaces</font></span>.</div></td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td height="46" class="GeneralText">&nbsp;</td>
      <td class="GeneralText"><div align="justify" class="GeneralText"><font face="Verdana, Arial, Helvetica, sans-serif">It is possible that the page you were looking for may have been moved,   updated or deleted.</font></div></td>
      <td class="GeneralText">&nbsp;</td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td class="GeneralText"><div align="justify"></div></td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td class="GeneralText"><div align="justify"><span class="Heading"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Please try the following options instead:</font></span></div></td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td class="GeneralText"><div align="justify"></div></td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td class="GeneralText"><div align="justify" class="GeneralText"><font face="Verdana, Arial, Helvetica, sans-serif">Return to the <a href="http://www.archiveservices.co.uk">Home Page</a></font> and search for the page you require </div></td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td class="GeneralText"><div align="justify"></div></td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td class="GeneralText"><div align="justify"><span class="GeneralText"><font face="Verdana, Arial, Helvetica, sans-serif">If you still encounter problems then please report this to the Webmaster by clicking Report below. </font></span></div></td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td class="GeneralText">&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td class="GeneralText"><form name="Error 404 Report" method="post" action="http://www.archiveservices.co.uk/form/formprocessorpro.php">
	  <input type="hidden" name="base_path" value="/www/hterror" />
	  <input type="hidden" name="r_referer" value="<?php echo $_SERVER['HTTP_REFERER']; ?>">
	  
      <input type="submit" name="Submit" value="Report Link">
      </form>
      </td>
      <td>&nbsp;</td>
    </tr>
  </table>
  <p>&nbsp;</p>
</center>
</body>
 
</html>

Open in new window

0
 
LVL 21

Expert Comment

by:nizsmo
ID: 20381847
The script works peerfect.

Lets say your script above is named 404.php, then save another file:

<html>
<a href="404.php">Test script!</a>
</html>

and you should see your script above working and capturing the referer.
0
 

Author Comment

by:d10u4v
ID: 20381927
All my error pages are stored on the Domain Server under www/hterror/

Could it be that the error pages are not saved in my html folder on my domain?

Anthony
0
 

Author Comment

by:d10u4v
ID: 20382516
Got it working.  One final question, How do i capture the address they were trying to get?

Anthony
0
 
LVL 21

Expert Comment

by:nizsmo
ID: 20385840
good on you!

>>How do i capture the address they were trying to get?

You can capture anyway you like, whether it is assigning it as a variable and printing it elsewhere, or sending it through a form and in the script which the form submits to get the referer like this:

<?php
...code...

$myreferer = $_POST["r_referer"];

// then do something with $myreferer, just as you would with a normal PHP variable.
?>
0

Featured Post

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Export Data from MySql Using PHP 16 67
allow link tag to be submit like form 15 60
What is key combo for a b with a forward slash through it? 12 64
Code planning methods/tools? 5 56
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
When it comes to write a Context Sensitive Help (an online help that is obtained from a specific point in state of software to provide help with that state) ,  first we need to make the file that contains all topics, which are given exclusive IDs. …
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question