How to check if the page exists?

Asked

Viewed 130 times

0

URL when the person is on the page to choose the episode can be http://www.localhost/seriados/serie/the-walking-dead or http://www.localhost/seriados/anime/the-walking-dead

URL when the person is on the page to watch can be http://www.localhost/seriados/serie/the-walking-dead/episodio-02-the-walking-dead/dublado or http://www.localhost/seriados/serie/the-walking-dead/episodio-02-the-walking-dead/legendado

//url padrao
$urlBase="http://www.localhost/seriados";

//pega o valor url do .htaccess
$url = $_GET['url'];

//cria um array depois da barra
$urlE = explode('/',$url);
if(isset($urlE['0'])){

   //valor serie ou anime
   $arquivo = $urlE['0'];

}

if(isset($urlE['1'])){

   //valor do slug "the-walking-dead"
   $post = $urlE['1'];
}

if(isset($urlE['2'])){

   //valor do slug_episodio "episodio-02-the-walking-dead"
   $ep = $urlE['2'];
}

if(isset($urlE['3'])){

   //valor do audio_episodio "dublado" ou "legendado"
   $audio = $urlE['3'];
}

//paginas do meu diretorio
$paginas = array('contato');

if(isset($arquivo) && in_array($arquivo,$paginas)){
   //se existir a pagina contato
   include_once("includes/$arquivo.php");
}

//se existir o valor $ep ($urlE['2']) na URL 
elseif(isset($ep) && !empty($ep)){
   include_once("includes/episodio.php");
}

//veririca se existe o valor "serie" ou "anime" ($urlE['0'])
elseif(isset($arquivo) && isset($post)){

    //se nao existir $urlE['1'] quer dizer ele esta na home
    if(empty($post)){
       header("Location: ".$urlBase."");
    }else{
       //pagina onde a pessoa escolhe a o episodio desejado
       include_once("includes/serie.php");
    }

}else{
    //se nao existir existir nenhuma acima, manda pra home
    include_once("includes/home.php");
}

So far so good, now let’s go to the page serie.php, now as I could check if the URL exists, I did so but some things do not work

//se nao existir nada na URL ($$urlE['0']) manda pra home 
if(empty($arquivo)){
  header("Location: ".$urlBase."");
}

//faz uma contagem na coluna slug_serie
$contaSeriado=$conn->prepare("SELECT COUNT(slug_serie) AS contaSlug FROM `seriados` WHERE `slug_serie` = '$post'");

if(isset($slug_serie)){
    $contaSeriado->bindValue(":slug_serie",$slug_serie,PDO::PARAM_STR);
}

$conta=$contaSeriado->rowCount();
$contaSeriado->execute();
$cs=$contaSeriado->fetchAll(PDO::FETCH_OBJ);

foreach($cs as $l){

   //se o slug_serie da URL for diferente do slug_serie banco manda pra home
   if($l->contaSlug<=0){
      header("Location: ".$urlBase."");
   }else{
     //exibo os detalhes da serie
   }

}

On this page the format of her URL and so on http://www.localhost/seriados/serie/the-walking-dead if the guy leaves her like this http://www.localhost/seriados/serie or write any name without the bar it does not redirect to home

I have another page too, which is responsible in displaying the episode chosen, in this I have no idea how to check the URL, the format of the URL of this page and so http://www.localhost/seriados/serie/the-walking-dead/episodio-02-the-walking-dead/dublado someone would tell me how to fix it, or give some idea ?

  • When you type a non-existent URL such as http://www.localhost/seriados/serie what happens? Error 404?

  • @Renatonascimento I do not have this page error, my goal is to send straight home, then what happens, the page is all white

  • 1

    read it here: https://answall.com/questions/1819/howto checkout se-uma-imagem-existe-num-url-remote

No answers

Browser other questions tagged

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