简体   繁体   English

如何使用我的 URL 中的 GET[] 解决这个 PHP 问题

[英]How can I solve this PHP issue with GET[] from my URL

if (isset($_GET['debug'])) {
    if(boolval($_GET['debug']) ? true : false)
    {
        echo "Using Distribution Certificate";
        stream_context_set_option($ctx, 'ssl', 'local_cert','cert.pem');
        $fp = stream_socket_client('ssl://gateway.push.apple.com:2195', $err, $errstr, 60, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $ctx);
    } else {
        echo "Using Development Certificate";
        stream_context_set_option($ctx, 'ssl', 'local_cert','certdevelopment.pem');
        $fp = stream_socket_client('ssl://gateway.sandbox.push.apple.com:2195', $err, $errstr, 60, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $ctx);
    }
}else{
    // Fallback behaviour goes here
    echo "Fallback Call To Use Distribution Certificate";
    stream_context_set_option($ctx, 'ssl', 'local_cert','cert.pem');
    $fp = stream_socket_client('ssl://gateway.push.apple.com:2195', $err, $errstr, 60, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $ctx);
}

When my URL is https://localhost/index.php?debug=true当我的 URL 是https://localhost/index.php?debug=true 时

I want to use the Distribution Certificate.我想使用分发证书。 If it's false then use the Development Certificate.如果为假,则使用开发证书。

If anything else is there then we use the Distribution certificate.如果还有其他东西,那么我们使用分发证书。

Unfortunately when my PHP script executes, it is always using the "Distribution Certificate".不幸的是,当我的 PHP 脚本执行时,它总是使用“分发证书”。 even when I set it to false.即使我将其设置为 false。 I think the "boolval" method is not working all the time.我认为“boolval”方法并非一直有效。

Instead of代替

if(boolval($_GET['debug']) ? true : false)

You should compare the values using您应该使用比较值

if($_GET['debug'] == 'true')

This is because both "true" and "false" evaluate to true when cast to a boolean.这是因为当转换为布尔值时,"true" 和 "false" 都评估为 true。 Check the test cases in the manual for more examples.查看手册中测试用例以获取更多示例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM