Page 4 of 4

Re: Custom errordocs not working in IE10

Posted: Wed Dec 04, 2013 12:16 pm
by Eric!
I did a little research and found google and W3C does not recommend the use of the meta refresh tags.
https://support.google.com/webmasters/answer/79812?hl=en wrote:This meta tag sends the user to a new URL after a certain amount of time, and is sometimes used as a simple form of redirection. However, it is not supported by all browsers and can be confusing to the user. The W3C recommends that this tag not be used. We recommend using a server-side 301 redirect instead.
I have to assume this would be even more true for missing pages (404 errors).

@simonwlewis a "server-side" redirect is when you use the header() to indicate the Status and present the next page. Like I've been suggesting.

Re: Custom errordocs not working in IE10

Posted: Wed Dec 04, 2013 12:27 pm
by simonmlewis
I don't think the PHP is working in the HTML error page:

Code: Select all

<!DOCTYPE html>
<head>

<?php header("Status: 404 Not Found"); 
include_once("http://www.site.co.uk/oops");
die();?>


<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

</head>

<body>
<p><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</p>
</body>
</html>

Re: Custom errordocs not working in IE10

Posted: Wed Dec 04, 2013 12:49 pm
by Eric!
You can not output headers to the browser after you've already sent html like <!doctype html>. You must always send the headers BEFORE echoing anything or sending any HTML. Before white spaces, before <!doctype>, before anything.

And is this http://www.site.co.uk/oops a real page? You want the included file to be your HTML with the error message. So the other HTML in this you've posted is redundant.

Really this code should be in your index.php and not on your error page. In your index.php page in pseudo code:

Code: Select all

<?php
$page=filter_var($_GET['page'],FILTER_SANITIZE_URL); // note the use of filter_var, not perfect but better than nothing

// TEST IF THE REQUESTED PAGE EXISTS OR NOT THEN REDIRECT AS NEEDED
if ($page exists){
  // 301 Moved Permanently
  header("Location: /".$page,TRUE,301); // assumes $page is in the root location
  die();
}
else{
  // page doesn't exist.  Error!
  header("Status: 404 Not Found");
  include_once("http://www.site.co.uk/error/not_found.html"); // show HTML 404 page
  die();
}
?>
Now this pseudo code can not be cut and pasted and expected to work. You have to adapt it to how your program is meant to work. So test for the missing page using whatever method you're using. Then redirect to the pages using whatever proper path/page name you need to use.

Re: Custom errordocs not working in IE10

Posted: Wed Dec 04, 2013 12:54 pm
by simonmlewis
This is how threads get too long.
I ask a question about redirection from within the not_found page, and you take me back to the template.
I've successfully worked out hwo to get them there, now I wana keep em there, and take them to the /oops page FROM there.

Re: Custom errordocs not working in IE10

Posted: Wed Dec 04, 2013 12:56 pm
by Eric!
If you don't understand what I'm telling you, post the full code of the page that needs to redirect and I will edit it for you. However I think the real problem is a misunderstanding of how to use redirection. (no pun intended). You do not want to do redirection in your "not_found page" because it is already too late. You redirect TO the 'not_found page' from the page that determines the requested page doesn't exist (which I assume is index.php).

Re: Custom errordocs not working in IE10

Posted: Wed Dec 04, 2013 1:02 pm
by simonmlewis
Ok the issue is with redirection.
If someone goes to http://www.site.co.uk/categ/51/shirts, then find the page of shirts.
But, if they go to http://www.categ/5144, then a) the HTACCESS won't understand it and b) 5144 doesnt' exist. so in theory all they get is a blank "categ" page.

With Firefox and now IE10 as well, this takes them to the /oops page.
If I do it using the method you described, then $page will exist, as it has found index.php?page=categ.

So I don't think I can use that code. But I suspect you have a means to say otherwise.

this is what I use now if a page called doesn't exist: such as http://www.site.co.uk/simon.

Code: Select all

if (isset($page))
{
  function getPage()
  {
  $thispage="includes/".$_GET['page'].".inc";

  if (file_exists($thispage)) 
  {
   include $thispage;
  } 
  else 
  {
  echo "<meta http-equiv='Refresh' content='0 ;URL=/oops'>";
  }
  }
  }   

Re: Custom errordocs not working in IE10

Posted: Wed Dec 04, 2013 1:26 pm
by Eric!
First off: how does this page http://www.site.co.uk/simon end up calling your getPage function? There is no query string!

Unfortunately you didn't post the full code, but I'll put in some comments to try to help. Here is your code after editing it. I don't understand why you are defining a function inside the if statement...but perhaps that is just to present the code all in one spot here?

Code: Select all

if (isset($page))
{
  function getPage()
  {
   $thispage="includes/".filter_var($_GET['page'],FILTER_SANITIZE_STRING).".inc"; // you might want to use add options of stripping low and high values too...and you need to protect against directory traversal too (google it)

   if (file_exists($thispage))
   {
     include $thispage; // if THIS script should stop here after showing the include page, then add die(), however if you need it to keep running then don't add die
   }
   else
   {
    //echo "<meta http-equiv='Refresh' content='0 ;URL=/oops'>";  // don't use this
    // page doesn't exist.  Error!
    header("Status: 404 Not Found");
    include_once("/oops"); // show HTML 404 page -- you might need to adjust the path depending on its location and is this an actual file?  It needs to be the HTML file containing the 404 error message in HTML or PHP
    die();
  }
 }
}
else
{
    //no query string = error too
    // page doesn't exist.  Error!
    header("Status: 404 Not Found");
    include_once("/oops"); // show HTML 404 page -- you might need to adjust the path depending on its location and is this an actual file?  It needs to be the HTML file containing the 404 error message in HTML or PHP
    die();
}