2015-09-04 70 views
-2
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); 
} 

当我的网址是https://localhost/index.php?debug=true我怎样才能解决GET []这个PHP问题从我的网址

我想使用的发布证书。如果它是假的,则使用开发证书。

如果有其他东西,那么我们使用分配证书。

不幸的是,当我的PHP脚本执行时,它总是使用“分发证书”。即使我把它设置为false。我认为“boolval”方法并非一直在运行。

+1

'boolval'不会做你认为它做的事。它*将传递给它的值作为布尔值转换。在PHP中,字符串“true”和“false”都转换为布尔值true。请参阅:http://php.net/manual/en/language.types.boolean.php#language.types.boolean.casting –

+0

因为字符串“true”将始终为真。这是一个字符串,因此将被评估为true(空字符串为false)。 – Andrew

+1

P.S.你可以做'if(boolval($ _ GET ['debug']))',这里没有理由使用'?:'。 –

回答

2

而不是

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

你应该使用

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

这是转换为布尔时,因为这两个“真”与“假”评估为真比较值。有关更多示例,请查看test cases in the manual