我正在尝试为现有代码添加第二个条件,但它似乎并没有起作用。
条件是:
以下是没有第二个条件的工作代码:http://pastebin.com/bfpNb9zw
以下是我的尝试:
基本上,我试图开始工作的这一部分是&& ($ca = '')
&& ($ca = '0')
&& ($ca = '1')
,但似乎$ ca无法在循环外读取
if(!function_exists('lookup')){
function lookup($chain, $type) {
$cacount = count($chain['tbsCertificate']['extensions']);
for($j = 0; $j < $cacount; $j++) {
$count = count($chain['tbsCertificate'][$type]['rdnSequence']);
$exists = array('utf8String', 'printableString', 'teletexString', 'bmpString', 'universalString', 'ia5String');
$oid = array('id-at-commonName');
for($i = 0; $i < $count; $i++) {
foreach($exists as $field) {
if(
array_key_exists($field, $chain['tbsCertificate'][$type]['rdnSequence'][$i][0]['value']) &&
in_array($chain['tbsCertificate'][$type]['rdnSequence'][$i][0]['type'], $oid)
) {
$value = $chain['tbsCertificate'][$type]['rdnSequence'][$i][0]['value'][$field];
return $value;
$ca = '';
if(isset($chain['tbsCertificate']['extensions'][$j]['extnValue']['cA'])) {
$ca = $chain['tbsCertificate']['extensions'][$j]['extnValue']['cA'];
}
}
}
}
}
return null;
}
}
if (lookup($chain, 'subject') != lookup($chain, 'issuer') && ($ca == '')) {
echo 'end entity';
}
elseif (lookup($chain, 'subject') != lookup($chain, 'issuer') && ($ca == '0')) {
echo 'secondary ca';
}
elseif (lookup($chain, 'subject') != lookup($chain, 'issuer') && ($ca == '1')) {
echo 'primary ca';
} else {
echo 'Root';
}
答案 0 :(得分:3)
您正在使用=
,它设置$ca
的值。您应该使用===
来检查值。
示例:
if (lookup($chain, 'subject') != lookup($chain, 'issuer') && ($ca === '')) {
echo 'end entity';
}
elseif (lookup($chain, 'subject') != lookup($chain, 'issuer') && ($ca === '0')) {
echo 'secondary ca';
}
elseif (lookup($chain, 'subject') != lookup($chain, 'issuer') && ($ca === '1')) {
echo 'primary ca';
} else {
echo 'Root';
}