PHP自动“获取"变数 [英] PHP Automatically "GET" Variables

查看:59
本文介绍了PHP自动“获取"变数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为公司设计一个新的网站,并且试图实现开关导航,这是我过去在所有站点上使用的导航.

I am desiging a new website for my company and I am trying to implement switch navigation which is what I have used on all my sites in the past.

<?php
switch($x) {

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

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

}
?>

由于某种原因,当我转到index.php?x = products时,什么都没发生,它仍然显示inc/main.php,换句话说,它没有从URL中检测到X变量.这和全局变量有关吗?

For some reason when I go to index.php?x=products nothing happens, it still displays inc/main.php, in other words it hasn't detected the X variable from the URL. Is this something to do with global variables?

推荐答案

是的,您的PHP配置正确已关闭register_globals,因为这确实不安全.

Yes, your PHP configuration has correctly got register_globals turned off, because that's incredibly insecure.

只需输入:

$x = $_REQUEST['x']

位于脚本顶部.

如果只希望它对GET HTTP方法有效,也可以使用$_GET.我见过有人声称$_REQUEST某种程度上是不安全的,但是没有证据支持这一点.

You can also use $_GET if you specifically only want this to work for the GET HTTP method. I've seen some people claim that $_REQUEST is somehow insecure, but no evidence to back that up.

这篇关于PHP自动“获取"变数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆