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

Asked

Viewed 1,869 times

1

Hello, I have the following condition:

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

but I’m having trouble because the cardapio.php can be accessed through GET as cardapio.php?etapa=2

How do I get my condition to accept menu.php access with GET variables

3 answers

2

Can do with strpos, 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 file name:

if(basename(__FILE__) != 'cardapio.php') {
    header('Location: cardapio.php');
}

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');
}

0

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

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

Browser other questions tagged

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