page with search get is not showing because of REQUEST_URI

2

Well, I'll try to make it happen!

I have a site in php where you have the config.php file with the following lines

<?php
$current_page_uri = $_SERVER['REQUEST_URI'];
$part_url = explode("/", $current_page_uri);
$page_name = end($part_url);
$email_id = "[email protected]";
?>

On the index.php page the following setting

<?php 
include "app/config.php";
include "app/detect.php";

if ($page_name=='') {
    include $browser_t.'/index.php';
}
elseif ($page_name=='index.php') {
    include $browser_t.'/index.php';
}
elseif ($page_name=='sobre.php') {
    include $browser_t.'/sobre.php';
}
elseif ($page_name=='galeria.php') {
    include $browser_t.'/galeria.php';
}
elseif ($page_name=='servicos.php') {
    include $browser_t.'/servicos.php';
}
elseif ($page_name=='contato.php') {
    include $browser_t.'/contato.php';
}
elseif ($page_name=='contato-post.php') {
    include $browser_t.'/contato.php';
    include 'app/contato.php';
}

else
{
    include $browser_t.'/404.html';
}

?>

When I enter normal pages as about.php , galeria.php , the browser opens normally.

I already have a problem with http://localhost/meusite/galeria.php , there are all the photos of the products coming from Mysql, and there is a pagination to advance the products on the pages.

When I select to advance a page of products in which the link takes the reference of the page that is, example http://localhost/meusite/galeria.php?pagina=2 the site does not open.

If I insert into index.php the line below it works.

elseif ($page_name=='galeria.php?pagina=2') {
    include $browser_t.'/galeria.php';
}

I have a problem also in the search button of the site that can search the product, when I search for example product code: "6554"

When I click on search it would have to open the page http://localhost/meusite/galeria_busca.php?id=6554&busca=

It just does not open either, but as a test I inserted the following line in index.php and it worked.

elseif ($page_name=='galeria_busca.php?id=6554&busca=') {
    include $browser_t.'/galeria_busca.php';
}

I would like the help of someone to tell me what I am doing wrong that is not opening normally without having to put the search paths in index.php because I have many products and it would be impracticable to create a line of code for each product code .

Any questions are available.

    
asked by anonymous 21.06.2018 / 20:42

1 answer

1
  

You get the final part of url http://localhost/meusite/galeria.php?pagina=2 and assign the variable $page_name which assumes the value galeria.php?pagina=2 and then compares this to galeria.php , of course it will not work, that is, there will not be include $browser_t.'/galeria.php'; That's what you're doing wrong !!

In% with%, see if there is $page_name = end($part_url); , if there is an explode and get the first part and assign the variable ?

  

A more direct way is to use strstr - find the first occurrence of a string

}elseif (strstr($page_name,"galeria.php")){

ideone example

About your comment $page_name

  

When you access ..... na minha .config não tem o "?" ..... ai has http://localhost/meusite/galeria.php?pagina=2 and its ? will return .config and therefore will not enter galeria.php?pagina=2 because elseif ($page_name=='galeria.php') { (which assumed $page_name ) is other than galeria.php?pagina=2

I would discard galeria.php and would do it as follows:

<?php 
$current_page_uri = $_SERVER['REQUEST_URI'];
$email_id = "[email protected]";
include "app/detect.php";

if (strstr($current_page_uri,"index.php'")){
    include $browser_t.'/index.php';
}
elseif (strstr($current_page_uri,"sobre.php")){
    include $browser_t.'/sobre.php';
}
elseif (strstr($current_page_uri,"galeria.php")){
    include $browser_t.'/galeria.php';
}
elseif (strstr($current_page_uri,"servicos.php")){
    include $browser_t.'/servicos.php';
}
elseif (strstr($current_page_uri,"contato.php")){
    include $browser_t.'/contato.php';
}
elseif (strstr($current_page_uri,"contato-post.php")){
    include $browser_t.'/contato.php';
    include 'app/contato.php';
}
else
{
include $browser_t.'/404.html';
}
?>
    
21.06.2018 / 23:14