Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/275.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP—是否可以在不满足条件的情况下执行if语句?_Php - Fatal编程技术网

PHP—是否可以在不满足条件的情况下执行if语句?

PHP—是否可以在不满足条件的情况下执行if语句?,php,Php,如果不满足条件,这样的代码是否可能执行,我要猜测密码,或者某种暴力方法 我只是问如果一个if语句可能会以某种方式中断,是否有任何方式让一个if语句出错,让用户在不知道密码的情况下执行下面的理论代码 我只是想澄清一下,我不是在猜测密码或任何类似的过度漏洞,我只是在讨论如果不满足语句条件,if语句是否可能执行,例如,如果服务器处于极端负载下,它是否会犯错误?否,如果包含else部分,如果不满足if条件,则流程将自动转移到else。回答您的主要问题否,if被破坏的可能性微乎其微。这将使目前生产中的代码

如果不满足条件,这样的代码是否可能执行,我要猜测密码,或者某种暴力方法

我只是问如果一个if语句可能会以某种方式中断,是否有任何方式让一个if语句出错,让用户在不知道密码的情况下执行下面的理论代码


我只是想澄清一下,我不是在猜测密码或任何类似的过度漏洞,我只是在讨论如果不满足语句条件,if语句是否可能执行,例如,如果服务器处于极端负载下,它是否会犯错误?否,如果包含
else
部分,如果不满足
if
条件,则流程将自动转移到
else

回答您的主要问题否,if被破坏的可能性微乎其微。这将使目前生产中的代码100%不可靠。你访问过多少有用户名和密码的网站,它们做的事情是相同的(有点类似)

您确实需要重新访问此代码,因为它应该是一致的、格式化的,并且在流中受到限制

您有2个模具版本(这不是最佳选择) 代码格式到处都是,你有逻辑检查,这实际上只是让流程更难遵循,没有任何好处

$example = 0;    

if ($password == "123") {
    $example = 1;
    }else{
    die("Incorrect Password");
    }    

    if ($example === 1) {
        echo "Conditions Met.";
        }else{
        echo "Conditions Not Met";
        die();
        }

    //Super important code that should not run if $example does not equal 1
重构这可以简单到:

$example = 0;    
//For the sake of simplicity I will assume you know this is not how to handle passwords in real life.

//If not please comment and I will give a better example. 

if ($password == "123") {
    $example = 1;
}else{
    //Die version 1
    die("Incorrect Password"); //If you are here then nothing below in this script will run.
}    

//Literally just a continuation of the code you have uptop?
if ($example === 1) {
    echo "Conditions Met.";
}else{
    //Die version 2
    echo "Conditions Not Met";
    die();
}

//This is the code that should be in the if.
//Super important code that should not run if $example does not equal 1

否。
if
语句的功能已经相当完善。问题是。。。为什么您认为PHP中的
if
关键字可能会被破坏?不,它不应该被破坏,否则它将是一个bug(不包括来自同一服务器上的程序的直接内存访问)不,它不是,但我不会使用
die()
来实现这一点。
if
语句不太可能“破坏”。但是,自身条件也可能受到攻击。有些情况下会出现缓冲区溢出、字符串中的早期空终止或编码攻击,这些情况在某些情况下会被误解。如其他人所述,
die
不应使用,因为在某些情况下可能会暴露安全相关信息。
//For the sake of simplicity I will assume you know this is not how to handle passwords in real life.

//If not please comment and I will give a better example. 

if ($password == "123") {
    //Super important code that should not run if bad password!
}else{
    //Killing a script is bad form
    //Redirect them to a login page or something.
}