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
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
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';
}
You are using =, which sets the value of $ca. You should be using === to check the 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';
}
Related
I'm really confused, because I have an if/else statement what works at a first integration in the system, but in a second case I must rewrite the function. My opinion is, that both statements has the same logic? Or isn't it?
Statement 1: works as intended in first integration of code, but not at the second integration (always the variable ba_geschaeftszeichen has a string lenght of zero):
if (
(isset($_POST['ba_geschaeftszeichen']) && ($kostentraeger == "sozialamt")) ||
(isset($_POST['pk_vnr']) && ($kostentraeger == "pflegekasse"))
) {
if (isset($_POST['ba_geschaeftszeichen']) && (strlen($_POST['ba_geschaeftszeichen']) > 0)) {
$ba_geschaeftszeichen = $_POST['ba_geschaeftszeichen'];
} else if (isset($_POST['pk_vnr']) && (strlen($_POST['pk_vnr']) > 0)) {
$ba_geschaeftszeichen = $_POST['pk_vnr'];
} else {
$ba_geschaeftszeichen = "";
}
} else { $ba_geschaeftszeichen = ""; }
Statement 2: only this code works at the second integration:
if (
(isset($_POST['ba_geschaeftszeichen']) && ($kostentraeger == "sozialamt")) ||
(isset($_POST['pk_vnr']) && ($kostentraeger == "pflegekasse"))
) {
if (isset($_POST['ba_geschaeftszeichen']) && (strlen($_POST['ba_geschaeftszeichen']) > 0)) {
$ba_geschaeftszeichen = $_POST['ba_geschaeftszeichen'];
} else {
$ba_geschaeftszeichen = "";
}
if (isset($_POST['pk_vnr']) && (strlen($_POST['pk_vnr']) > 0)) {
$ba_geschaeftszeichen = $_POST['pk_vnr'];
} else {
$ba_geschaeftszeichen = "";
}
} else { $ba_geschaeftszeichen = ""; }
In statement 1, you reach
if (isset($_POST['pk_vnr']) && (strlen($_POST['pk_vnr']) > 0))
only if
if (isset($_POST['ba_geschaeftszeichen']) && (strlen($_POST['ba_geschaeftszeichen']) > 0))
is false.
In statement 2, you reach
if (isset($_POST['pk_vnr']) && (strlen($_POST['pk_vnr']) > 0))
regardless.
I am using opencart 2.0 and i have made custom registeration page in opencart.After successful registration i am redirecting to myaccount page but it will redirect to login page.
Can anybody help me in this to sort out the problem?
Here's my controller code :-
public function register() {
$this->load->language('checkout/checkout');
$json = array();
//if (!$json) {
$this->load->model('account/customer');
if ((utf8_strlen(trim($this->request->post['firstname'])) < 1) || (utf8_strlen(trim($this->request->post['firstname'])) > 32)) {
$json['error']['firstname'] = $this->language->get('error_firstname');
}
/*if ((utf8_strlen(trim($this->request->post['lastname'])) < 1) || (utf8_strlen(trim($this->request->post['lastname'])) > 32)) {
$json['error']['lastname'] = $this->language->get('error_lastname');
}*/
if ((utf8_strlen($this->request->post['email']) > 96) || !preg_match('/^(([^<>()[\]\\.,;:\s#\"]+(\.[^<>()[\]\\.,;:\s#\"]+)*)|(\".+\"))#((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/', $this->request->post['email'])) {
$json['error']['email'] = $this->language->get('error_email');
}
if ($this->model_account_customer->getTotalCustomersByEmail($this->request->post['email'])) {
$json['error']['warning'] = $this->language->get('error_exists');
}
if ((utf8_strlen($this->request->post['telephone']) < 3) || (utf8_strlen($this->request->post['telephone']) > 32)) {
$json['error']['telephone'] = $this->language->get('error_telephone');
}
/*if ((utf8_strlen(trim($this->request->post['address_1'])) < 3) || (utf8_strlen(trim($this->request->post['address_1'])) > 128)) {
$json['error']['address_1'] = $this->language->get('error_address_1');
}
if ((utf8_strlen(trim($this->request->post['city'])) < 2) || (utf8_strlen(trim($this->request->post['city'])) > 128)) {
$json['error']['city'] = $this->language->get('error_city');
}
$this->load->model('localisation/country');
$country_info = $this->model_localisation_country->getCountry($this->request->post['country_id']);
if ($country_info && $country_info['postcode_required'] && (utf8_strlen(trim($this->request->post['postcode'])) < 2 || utf8_strlen(trim($this->request->post['postcode'])) > 10)) {
$json['error']['postcode'] = $this->language->get('error_postcode');
}
if ($this->request->post['country_id'] == '') {
$json['error']['country'] = $this->language->get('error_country');
}
if (!isset($this->request->post['zone_id']) || $this->request->post['zone_id'] == '') {
$json['error']['zone'] = $this->language->get('error_zone');
}*/
if ((utf8_strlen($this->request->post['password']) < 4) || (utf8_strlen($this->request->post['password']) > 20)) {
$json['error']['password'] = $this->language->get('error_password');
}
if ($this->request->post['confirm'] != $this->request->post['password']) {
$json['error']['confirm'] = $this->language->get('error_confirm');
}
/*if ($this->config->get('config_account_id')) {
$this->load->model('catalog/information');
$information_info = $this->model_catalog_information->getInformation($this->config->get('config_account_id'));
if ($information_info && !isset($this->request->post['agree'])) {
$json['error']['warning'] = sprintf($this->language->get('error_agree'), $information_info['title']);
}
} */
// Customer Group
if (isset($this->request->post['customer_group_id']) && is_array($this->config->get('config_customer_group_display')) && in_array($this->request->post['customer_group_id'], $this->config->get('config_customer_group_display'))) {
$customer_group_id = $this->request->post['customer_group_id'];
} else {
$customer_group_id = $this->config->get('config_customer_group_id');
}
// Custom field validation
$this->load->model('account/custom_field');
$custom_fields = $this->model_account_custom_field->getCustomFields($customer_group_id);
foreach ($custom_fields as $custom_field) {
if ($custom_field['required'] && empty($this->request->post['custom_field'][$custom_field['location']][$custom_field['custom_field_id']])) {
$json['error']['custom_field' . $custom_field['custom_field_id']] = sprintf($this->language->get('error_custom_field'), $custom_field['name']);
}
}
//}
//if (!$json) {
$customer_id = $this->model_account_customer->addCustomer($this->request->post);
// Clear any previous login attempts for unregistered accounts.
$this->model_account_customer->deleteLoginAttempts($this->request->post['email']);
$this->session->data['account'] = 'register';
$this->load->model('account/customer_group');
$customer_group_info = $this->model_account_customer_group->getCustomerGroup($customer_group_id);
/*if ($customer_group_info && !$customer_group_info['approval']) {
$this->customer->login($this->request->post['email'], $this->request->post['password']);
// Default Payment Address
$this->load->model('account/address');
$this->session->data['payment_address'] = $this->model_account_address->getAddress($this->customer->getAddressId());
if (!empty($this->request->post['shipping_address'])) {
$this->session->data['shipping_address'] = $this->model_account_address->getAddress($this->customer->getAddressId());
}
} else {*/
$json['redirect'] = $this->url->link('account/account');
//}
unset($this->session->data['guest']);
unset($this->session->data['shipping_method']);
unset($this->session->data['shipping_methods']);
unset($this->session->data['payment_method']);
unset($this->session->data['payment_methods']);
// Add to activity log
$this->load->model('account/activity');
$activity_data = array(
'customer_id' => $customer_id,
'name' => $this->request->post['firstname'] . ' ' . $this->request->post['lastname']
);
$this->model_account_activity->addActivity('register', $activity_data);
//}
$this->response->addHeader('Content-Type: application/json');
$this->response->setOutput(json_encode($json));
}
I have a list of items, sorted into groups. When the user is not logged in, I print only the items that don't require login.
$previous_group = '';
foreach ($arr as $item) {
if($previous_group != $item['group']) {
// Add dividers
if($previous_group != '') echo '</ul>';
echo '<h3>'.$item['group'].'</h3>';
echo '<ul>';
}
$previous_group = $item['group'];
if($item['login_required'] !== 'true' || ($item['login_required'] == 'true' && $isLoggedIn != false)) {
echo '<li>'.$item['title'].'</li>';
}
}
echo '</ul>';
PhpFiddle
How can I hide the header for a group that doesn't have any items because the user isn't logged in? For example, the "food" category in the PhpFiddle example.
I could just go through the array twice, but is there a more efficient way to do it?
try
$previous_group = '';
foreach ($arr as $item) {
if($previous_group != $item['group'] && ($item['login_required'] == 'false' || $isLoggedIn == 'true')) {
// Add dividers
if($previous_group != ''){echo '</ul>';}
echo '<h3>'.$item['group'].'</h3>';
echo '<ul>';
}
$previous_group = $item['group'];
if($item['login_required'] !== 'true' || ($item['login_required'] == 'true' && $isLoggedIn != false)) {
echo '<li>'.$item['title'].'</li>';
}
}
echo '</ul>';
If you want just one iteration:
$previous_group = '';
$group_content = '';
$last_key = end(array_keys($arr));
foreach ($arr as $key => $item) {
if (!$previous_group) $previous_group = $item['group'];
if ($key === $last_key && $previous_group == $item['group'] && ($item['login_required'] !== 'true' || ($item['login_required'] == 'true' && $isLoggedIn != false))) $group_content .= '<li>'.$item['title'].'</li>';
if ($group_content) {
echo '<h3>'.$item['group'].'</h3>';
echo '<ul>';
echo $group_content;
echo '</ul>';
}
$previous_group = $item['group'];
$group_content = '';
}
if($item['login_required'] !== 'true' || ($item['login_required'] == 'true' && $isLoggedIn != false)) {
$group_content .= '<li>'.$item['title'].'</li>';
}
}
However, doing more than one iteration will give you cleaner code.
This works
If ($flag != 'u') { stuff.. }
This also works.
If ($id != 0) { stuff.. }
But these don't seem to work for me....
If ( ($flag != 'u') || ($id != 0) ) { stuff.. }
If ( ($flag != 'u') or ($id != 0) ) { stuff.. }
If ($flag != 'u') || ($id != 0) { stuff.. }
If ($flag != 'u') or ($id != 0) { stuff.. }
If ( $flag != 'u' || $id != 0 ) { stuff.. }
If ( $flag != 'u' or $id != 0 ) { stuff.. }
Any idea why? and what format should I use for this in PHP?
Your code actually works. I tried this
<?php
$flag= u;
$id= 0;
if ( ($flag != 'u') || ($id != 0) )
{
echo "Hi";
}
?>
The code simple says if $flag not equal to u or if $id not equals 0 then echo hi in page.
Is that your logic?
The problem might be in your logic I hope!
Is there any way to go to the else if body after the if condition is sucessfully entered?
Is there any way to go to the else if body after the if condition is sucessfully entered?
if ($axisX == $axisXOne) { /* Main IF Statement */
if($axisY =='0' && $axisYOne == '1') { $second = '2';}
else if($axisY =='0' && $axisYOne == '2') { $second = '1';}
else if($axisY =='1' && $axisYOne == '0') { $second = '2';}
else if($axisY =='1' && $axisYOne == '2') { $second = '0';}
else if($axisY =='2' && $axisYOne == '0') { $second = '1';}
else if($axisY =='2' && $axisYOne == '1') { $second = '0';}
if (($_POST['button'.$axisX.$second] == null) && ($curVal != $axisX.$second)){ /* Inner IF Statement */
echo $axisX.$second;
}
}
else if ($axisY == $axisYOne) { /* Main ELSE IF statement */
if($axisX =='0' && $axisXOne == '1') { $second = '2';}
else if($axisX =='0' && $axisXOne == '2') { $second = '1';}
else if($axisX =='1' && $axisXOne == '0') { $second = '2';}
else if($axisX =='1' && $axisXOne == '2') { $second = '0';}
else if($axisX =='2' && $axisXOne == '0') { $second = '1';}
else if($axisX =='2' && $axisXOne == '1') { $second = '0';}
if($_POST['button'.$second.$axisY] == null) {/* Inner IF Statement */
echo $second.$axisY;
}
}
else if ($xAxis == $yAxis && $xAxisOne == $yAxisOne) { /* other Main ELSE IF Statement*/
if($comVal[0] == '00' && $comVal[1] == '11') { $diagon = '22';}
else if($comVal[0] == '00' && $comVal[1] == '22') { $diagon = '11';}
else if($comVal[0] == '11' && $comVal[1] == '00') { $diagon = '22';}
else if($comVal[0] == '11' && $comVal[1] == '22') { $diagon = '00';}
else if($comVal[0] == '22' && $comVal[1] == '00') { $diagon = '11';}
else if($comVal[0] == '22' && $comVal[1] == '11') { $diagon = '00';}
if($_POST['button'.$diagon] == null) {
echo $diagon;
}
}
If Main IF Statement evaluates true and Inner IF Statement evalautes false then go to Main ELSE IF ladder. If Main IF Statement evaluates true and Inner IF Statement evalautes true then stop loop . If Main IF Statement evaluates false, directly go to Main ELSE IF Statement
If Main ELSE IF Statement evaluates true and Inner IF Statement evalautes false then go to Main ELSE IF ladder. If Main ElSE IF Statement evaluates true and Inner IF Statement evalautes true ,then stop loop .If Main ELSE IF Statement evaluates false, directly go to other Main ELSE IF Statements
Try this:
$success = true;
if($a == $Xaxis && $b == $yaxis) {
$zAxis = $Xaxis + $yaxis;
$success = $Xaxis != $zAxis;
}
if( ($b == $Xaxis && $a == $yaxis) || !$success) {
// do stuff here
}
Or something along those lines.