PHP automatically "get" Variables

I am going to create a new site for my company, and I am trying to implement the switch navigation that I used on all my sites in the past.

<?php
switch($x) {

default:
include("inc/main.php");
break;

case "products":
include("inc/products.php");
break;

}
?>

For some reason, when do I go to index.php? x = nothing happens, it still displays inc / main.php, in other words, it did not find the X variable from the url. Is this related to global variables?

+3
source share
4 answers

Yes, your configuration PHP has correctly received register_globalsis disabled because it is incredibly dangerous.

Just put:

$x = $_REQUEST['x']

at the top of your script.

$_GET, , GET HTTP. , , $_REQUEST - , , .

+15

, - register_globals, . PHP 6.0! switch($_GET['x']) {.

+5

$_GET . register_globals, , .

+1

You can use http://php.net/manual/es/function.extract.php to extract variables if you want to do this, but keep in mind that this allows any user to set variables with the content that they want in your script, which makes it as volatile as using register_globals

0
source

Source: https://habr.com/ru/post/1699044/


All Articles