Display error while loading page with url not found

Asked

Viewed 830 times

1

I wonder if it is possible to create an iframe with URL error ex: if the url is not found type that browser error when the site is outside or the network is disconnected.

  • 3

    Can you explain it better? Do you want if the user opens a page that does not exist to show this error in an iframe? how your site navigation works?

  • In case the client will get an html file inside it will this the iframe

  • 2

    "In case the client will keep an html file inside it will this to iframe", sorry but I need a more complete explanation. Maybe it is my Portuguese of Portugal that prevents you to understand your idea completely but if you can explain even better. See Help Center How to Ask

1 answer

1

There are some ways you create an error page to replace the default browser error page when there is no particular file in the folder.

A good option would be to create an array of pages that exist on your site within your index. If in the url there is no such page, it includes an error page "more beautiful".

let’s see with this url:

www.site.com.br? page=hacker

index php.

     // vamos verificar se existe o $_GET['pagina']
    // no caso desta url esta condição é verdadeira então ele entra no primeiro if
    if(isset($_GET['pagina']){

    // criaremos um array das páginas que existem no site.
    $paginasExistentes = array('home', 'produto', 'contato');

     // agora vamos verificar se a página $_GET['pagina'] está dentro das $paginasExistentes
       // ( nesta url não vai estar, pois o valor dela é "hack"

       $paginaUrl = $_GET['pagina'];           

       if(array_search($paginaUrl, $paginasExistentes) != false ){

       // se a condição for verdadeira, inclua a página selecionada

       include($paginasExistentes.".html");

       } else {

       // se não inclua a página erro

       include("paginaErro.html");

       }

    } **else** {

    // se não existir o $_GET['pagina'], você precisa analisar a url:

    $url = $_SERVER['REQUEST_URI'];

        if($url == 'index.php' || $url == ''){

         // se a url for index.php ou vazia inclua pagina home            

          include("home.html");

        } else {

        // se não inclua a página erro             

        include("paginaErro.html");

        }

    }

Another example:

www.site.com.br/hacker

in this url, the first "if" condition of the code is false, so it will go to the last Else and include the error page

on your error page you can include the iframe you need

hope I’ve helped

Browser other questions tagged

You are not signed in. Login or sign up in order to post.