php - Need help to add second condition to existing code -
i trying add second condition existing code doesn't seem working.
the conditions are:
- compare 2 strings, different arrays (working)
- and check value of third string different array (not working)
here working code without second condition: http://pastebin.com/bfpnb9zw
here attempt:
basically, bit trying working part && ($ca = '')
&& ($ca = '0')
&& ($ca = '1')
seems $ca not able read outside loop
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 $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'; }
you using =
, sets value of $ca
. should using ===
check value, instead.
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'; }
Comments
Post a Comment