热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

使用收取($_REQUEST[p])或$_REQUEST[p]-Usingisset($_REQUEST[“p”])or$_REQUEST[“p”]

Sometimeago,Iwasinainternship,andIwasworkingasajuniorweb-developer.Whileworkingand

Sometime ago, I was in a internship, and I was working as a junior web-developer. While working and learning, I noticed that when changing pages, instead of using isset($_POST/GET/REQUEST["var"]) they just used $_POST/GET/REQUEST["var"].

不久前,我还在实习,我是一名初级网页开发员。在工作和学习的过程中,我注意到,在更改页面时,使用的不是isset($_POST/GET/REQUEST["var"]),而是使用$_POST/GET/REQUEST["var"]。

So, later I came home, and tried the same thing. What happens ? Every-time I come across a if() to verify that, I have to use isset(), otherwhise it gives me an error. But notice one thing, my url is this:

所以,后来我回家,尝试了同样的事情。会发生什么呢?每次我遇到一个if()来验证它,我必须使用isset(),否则它会给我一个错误。但是注意一件事,我的网址是

?p=sub_artigo&id=2

So, when I do the if() condition:

当我做if()条件时

if(isset($_REQUEST["p"])=="procurar" && $_REQUEST['cont']){

It doesn't show errors, but if I take of the isset(), it gives the usual error that I see in the forums and here.

它没有显示错误,但是如果我使用isset(),它给出了我在论坛和这里看到的常见错误。

So my question is, why doesn't show the error for the second variable ?

我的问题是,为什么不显示第二个变量的误差?

Note: p->string;id->int

注意:p - >字符串;id - > int

3 个解决方案

#1


6  

They have error_reporting turned down, which is nice because it means you can do things like

他们有错误报告被拒绝,这很好,因为这意味着你可以做类似的事情。

if ($_POST['whatever']) { ... }

instead of

而不是

if (isset($_POST['whatever'])) { ... }

but it also stops you from seeing other possibly pertinent errors.

但它也阻止你看到其他可能的相关错误。

this setting is found in the php.ini file under the variable error_reporting.

该设置在php中找到。在变量error_reporting下的ini文件。

More information on the ini file can be found here: http://php.net/manual/en/ini.php

更多关于ini文件的信息可以在这里找到:http://php.net/manual/en/ini.php。

also, isset($_REQUEST["p"])=="procurar" while sytactically correct, is never going to return true, because isset() returns a boolean value.

同样,isset($_REQUEST["p"])=="拉皮条",而在sytac正确的情况下,永远不会返回true,因为isset()返回一个布尔值。

what you want is isset($_REQUEST['p']) && $_REQUEST['p'] == 'procurar'

你想要的是isset($_REQUEST['p']) & $_REQUEST['p'] = ' '

#2


5  

RTM: http://php.net/isset

RTM:http://php.net/isset

isset() returns a boolean TRUE/FALSE. It will NEVER return a string, so this statement

isset()返回一个布尔值TRUE/FALSE。它永远不会返回一个字符串,所以这个语句。

if(isset($_REQUEST["p"])=="procurar" && $_REQUEST['cont']){ 

can NEVER succeed, because isset() will never EVER be equal to procurar, so the ['cont'] check will never be evaluated.

永远不会成功,因为isset()永远不会等于代理,所以['cont']检查永远不会被评估。

#3


0  

When the first statement is false, PHP does not bother triyng the rest of the if statement.

当第一个语句为false时,PHP就不会对if语句的其余部分产生影响。

I always use the following check on every $_REQUEST, $_POST or $_GET key:

我总是在每个$_REQUEST、$_POST或$_GET键中使用以下检查:

function ifSet($key) {   
    return (isset($_REQUEST[$key]) && $_REQUEST[$key])?$_REQUEST[$key]:'';
}

This will never give you any warnings, even if error_reporting is set to E_ALL.

这不会给您任何警告,即使error_reporting被设置为E_ALL。

The 'isset' checks if the $key is set and after that it checks if $key has a value.

“isset”检查$key是否设置,然后检查$key是否具有值。


推荐阅读
author-avatar
拍友2502862603
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有