I am trying to add a second condition to existing code but it doesn't seem to be working.
我试图为现有代码添加第二个条件,但它似乎没有工作。
The conditions are:
条件是:
- Compare two strings, from different arrays (working)
- And check the value of a third string from a different array (not working)
比较来自不同阵列的两个字符串(工作)
并检查来自不同数组的第三个字符串的值(不工作)
Here is the working code without the second condition: http://pastebin.com/bfpNb9zw
这是没有第二个条件的工作代码:http://pastebin.com/bfpNb9zw
Here is my attempt:
这是我的尝试:
Basically, the bit I am trying to get working is this part && ($ca = '')
&& ($ca = '0')
&& ($ca = '1')
but it seems $ca is not able to be read outside the loop
基本上,我试图工作的这一部分是&&($ 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';
}
1 个解决方案
#1
You are using =
, which sets the value of $ca
. You should be using ===
to check the value, instead.
您正在使用=,它设置$ ca的值。您应该使用===来检查值。
Example:
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';
}
#1
You are using =
, which sets the value of $ca
. You should be using ===
to check the value, instead.
您正在使用=,它设置$ ca的值。您应该使用===来检查值。
Example:
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';
}