How to make '$ _SERVER [' REQUEST_URI ']' accept GET variables

1

Hello, I have the following condition:

  if($_SERVER['REQUEST_URI'] != '/painel/cardapio.php'){
        header('Location: cardapio.php');
      }

But I'm having trouble because cardapio.php can be accessed through GET as cardapio.php?etapa=2

How do I make my condition accept cardapio.php access with GET variables

    
asked by anonymous 30.06.2016 / 17:47

3 answers

1

Thanks to Miguel's help I was able to solve the problem using the following solution

$isCardapio= strpos($_SERVER['REQUEST_URI'], '/painel/cardapio.php');
if($isCardapio=== false){
  header('Location: cardapio.php');
}
    
30.06.2016 / 18:06
2

You can do with strpos , it can be used to see if a string contains any set of chars:

if(strpos($_SERVER['REQUEST_URI'], '/painel/cardapio.php') === False) { // caso não contenha vamos redirecionar
    header('Location: cardapio.php');
}

Or you can go by filename:

if(basename(__FILE__) != 'cardapio.php') {
    header('Location: cardapio.php');
}
    
30.06.2016 / 17:55
0

I think I could use $ _SERVER ['SCRIPT_NAME']

if ($_SERVER['SCRIPT_NAME']!= '/painel/cardapio.php') {
      header('Location: cardapio.php')
}
    
30.06.2016 / 18:08