Send vairables to php via bash CURL - php

I have a code like this:
<?php
$steamid64="76561197987276114"; //YOUR STEAM ID 64
echo "<br><br>Steamid32: ".getSteamId32($steamid64);
echo "<br><br>Steamid64: ".getSteamID64(getSteamId32($steamid64)); // 76561197985756607
//OBTER STEAM ID 64
function getSteamID64($id) {
if (preg_match('/^STEAM_/', $id)) {
$parts = explode(':', $id);
return bcadd(bcadd(bcmul($parts[2], '2'), '76561197960265728'), $parts[1]);
} elseif (is_numeric($id) && strlen($id) < 16) {
return bcadd($id, '76561197960265728');
} else {
return $id; // We have no idea what this is, so just return it.
}
}
function parseInt($string) {
// return intval($string);
if(preg_match('/(\d+)/', $string, $array)) {
return $array[1];
} else {
return 0;
}
}
function getSteamId32($id){
// Convert SteamID64 into SteamID
$subid = substr($id, 4); // because calculators are
$steamY = parseInt($subid);
$steamY = $steamY - 1197960265728; //76561197960265728
if ($steamY%2 == 1){
$steamX = 1;
} else {
$steamX = 0;
}
$steamY = (($steamY - $steamX) / 2);
$steamID = "STEAM_0:" . (string)$steamX . ":" . (string)$steamY;
return $steamID;
}
?>
The question is: How do I make $steamid64 readable? I mean, without form. So it could be posted by curl from linux bash and reply (return $steamID;) received.
Sorry for a very newb question. Thanks in advance.

i voted to close your question as unclear, but my best guess is that you want to change
<?php
$steamid64="76561197987276114"; //YOUR STEAM ID 64
to
<?php
$steamid64=$_POST['steamid64']??''; //YOUR STEAM ID 64
if(empty($steamid64) || !is_string($steamid64)){
http_response_code(400);
die("missing POST parameter steamid64!");
}
then you can do
curl -d "steamid64=76561197987276114" http://127.0.0.1/page.php
(but again, idk what you're asking, hence the close-vote.)

Related

Create a recursive function with an array

I have a function but can't success to make it recursive.
This is my function without recursion :
function resolution_recursion($tab1, $tab2){
$solution = [];
foreach($tab2 as $nb2){
foreach($tab1 as $nb1){
if(($nb2 + $nb1)%2 != 1){
$solution[] = $nb2 + $nb1;
}
}
}
return $solution;
}
And I would like to make it recursive to make it work like :
$nb_ajout = [2];
$next = [[1,2],[3,4],[5,6],[7,8]];
resolution_recursion(
resolution_recursion(
resolution_recursion(
resolution_recursion($nb_ajout, $next[0]),
$next[1]),
$next[2]),
$next[3]);
I can't find the solution, if you can help me.
Something like this would do the trick...
function resolution_recursion($tab1, $tab2, $solution = [])
{
if (empty($tab2)) {
return $solution;
}
$set = array_shift($tab2);
foreach($set as $nb2){
foreach($tab1 as $nb1){
if(($nb2 + $nb1)%2 != 1){
$solution[] = $nb2 + $nb1;
}
}
}
if (!empty($tab2)) {
return resolution_recursion($tab1, $tab2, $solution);
}
return $solution;
}
You can find a demo here (the output however means absolutely nothing to me though so hopefully it means something to you lol)
I think I have found something, not using recursion :
function resolution_recursion($tab1, $tab2){
$solution = [];
$solution[-1] = $tab1;
foreach($tab2 as $key => $tab){
foreach($tab as $nb2){
foreach($solution[$key-1] as $nb1){
if(($nb2 + $nb1)%2 != 1){
$solution[$key][] = $nb2 + $nb1;
}
}
}
}
return $solution;
}

Get return values of code with tokenizer

I'm trying to parse PHP source code with the token_get_all(). So far everything worked out with that function, but now i need a way to get the return values of methods.
Identifying where a return is done isn't the problem. I just see no way of getting the piece of code that comes after the return value.
For example for this piece of code:
<?php
class Bla {
public function Test1()
{
$t = true;
if($t) {
return 1;
}
return 0;
}
public function Test2()
{
echo "bbb";
return; // nothing is returned
}
public function Test3()
{
echo "ccc";
$someval1 = 1;
$someval2 = 2;
return ($someval + $otherval)*2;
}
}
?>
I'm using get_token_all() to identify where a return is done:
$newStr = '';
$returnToken = T_RETURN;
$tokens = token_get_all($source);
foreach ($tokens as $key => $token)
{
if (is_array($token))
{
if (($token[0] == $returnToken))
{
// found return, now get what is returned?
}
else
{
$token = $token[1];
}
}
$newStr .= $token;
}
I have no clue how to get the piece of code that is actually returned. That is what i want to get.
Anyone any idea how i could do this?
Perhaps this might help. Though I curious to know what you are ultimately trying to do.
$tokens = token_get_all($str);
$returnCode = '';
$returnCodes = array();
foreach ($tokens as $token) {
// If return statement start collecting code.
if (is_array($tokens) && $token['0'] == T_RETURN) {
$returnCode .= $token[1];
continue;
}
// if we started collecting code keep collecting.
if (!empty($returnCode)) {
// if we get to a semi-colon stop collecting code
if ($token === ';') {
$returnCodes[] = substr($returnCode, 6);
$returnCode = '';
} else {
$returnCode .= isset($token[1]) ? $token[1] : $token;
}
}
}

if else simple beginner issue

Good day guys,
I've made a sweet favorites function with php mysql and ajax, and its working great. Now I want to show 'favorite' when favorite = 0 and show 'unfavorite' when favorite = 1
if ($favorites == 0) {
$favorite = 'Favorite';
}
if ($favorites == 1) {
$unfavorite = 'unFavorite';
}
and echo it in the row as :
<div id="favorites">' .($favorite). ' ' .($unfavorite). '</div>
The problem is: when favorite = 0, both $favorite and $unfavorite are being shown. When favorite = 1 only $unfavorite is being shown correctly. Of course it should be $favorite OR $unfavorite. I assume the problem is clear and simple to you, please assist :)
Thanks in advance
It's easier to use just one variable:
$text = ''
if ($favorites == 0) {
$text = 'Favorite';
} else {
$text = 'unFavorite';
}
...
echo $text;
If you want to check $favorite, you are using the wrong variable in your control statement. Also, it is better coding practice to use elseif rather than if for that second if. One more thing: it's easier to manage one resulting variable.
$output = "";
if ($favorite == 0) {
$output = 'Favorite';
}
elseif ($favorite == 1) {
$output = 'unFavorite';
}
...
echo $output; // Or whatever you want to do with your output
Is $favorites an integer?
Anyway try using three equal signs (===) or else instead of the second if:
if ( $favorites === 0 )
{
// ...
}
else // or if ($favorites === 1)
{
// ...
}
You're making a toggle, so you only need one variable:
if(empty($favourites)){
$fav_toggle = 'Favorite';
} else {
$fav_toggle = 'unFavorite';
}
echo $fav_toggle;
Same code is working on me if I assigned $favorites = 0; or $favorites = 1;
You can also use if else
$favorites = 1;
if ($favorites == 0) {
$favorite = 'Favorite';
}
else if ($favorites == 1) {
$unfavorite = 'unFavorite';
}

php foreach results

foreach ($flr_array as $flr) {
if (!($flr = trim($flr)))
continue;
//list($flr, $keyword) = explode('|', $flr, 2);
$ip = '';
$err_msg = isValidFLR($flr, $ip);
if (!$err_msg) {
list($randlink, $lastid, $scr) = addLink($flr, $ip);
$flr = stripslashes($flr);
$url_array[$i]['number'] = $i + 1;
$url_array[$i]['flr'] = $flr;
$url_array[$i]['flr_substr'] = (strlen($flr) > 33) ? substr($flr, 0, 33) . '...' : $flr;
$url_array[$i]['randlink'] = $randlink;
$url_array[$i]['fullrand'] = $config['indexurl'] . $config['mod_rewrite_char'] . $randlink;
$url_array[$i]['scr'] = $scr;
$url_array[$i]['id'] = $lastid;
$url_array[$i]['flr_length'] = strlen($flr);
$url_array[$i++]['randlink_length'] = strlen($config['indexurl'] . $config['mod_rewrite_char'] . $randlink);
////
//$smarty->assign("flr_length", strlen($_REQUEST['flr']));
//$smarty->assign("randlink_length", strlen($config['indexurl'] . $config['mod_rewrite_char'] . $randlink));
////
} else {
js_alert($err_msg);
}
}
In function isValidFLR these is part of captcha check:
if ($config['captcha_check']) {
if (verifyCaptcha() == false) {
return 'Wrong code!';
}
}
Let's say in textarea i enter:
google.com
google.de
google.net
and enter wrong captcha code, so it gives me 3 messages of Wrong code!
It's happen i think because of foreach. Any ideas how to make in foreach display only one error message ?
Your question is hard to understand but I think you are right (in the foreach)....
if err_msg <> '' then you should put a break in your code to get out of the foreach (if that is what you want).
else {
js_alert($err_msg);
break; //this will break out of for loop
//or return false if it a function
}

Getting header response code

This is part of a PHP script I am putting together. Basically a domain ($domain1) is defined in a form and a different message is displayed, based on the response code from the server. However, I am having issues getting it to work. The 3 digit response code is all I am interested in.
Here is what I have so far:
function get_http_response_code($domain1) {
$headers = get_headers($domain1);
return substr($headers[0], 9, 3);
foreach ($get_http_response_code as $gethead) {
if ($gethead == 200) {
echo "OKAY!";
} else {
echo "Nokay!";
}
}
}
$domain1 = 'http://google.com';
function get_http_response_code($domain1) {
$headers = get_headers($domain1);
return substr($headers[0], 9, 3);
}
$get_http_response_code = get_http_response_code($domain1);
if ( $get_http_response_code == 200 ) {
echo "OKAY!";
} else {
echo "Nokay!";
}
If you have PHP 5.4.0+ you can use the http_response_code() function. Example:
var_dump(http_response_code()); // int(200)
Here is my solution for people who need send email when server down:
$url = 'http://www.example.com';
while(true) {
$strHeader = get_headers($url)[0];
$statusCode = substr($strHeader, 9, 3 );
if($statusCode != 200 ) {
echo 'Server down.';
// Send email
}
else {
echo 'oK';
}
sleep(30);
}
You directly returned so function wont execute further foreach condition which you written. Its always better to maintain two functions.
function get_http_response_code($domain1) {
$headers = get_headers($domain1);
return substr($headers[0], 9, 3); //**Here you should not return**
foreach ($get_http_response_code as $gethead) {
if ($gethead == 200) {
echo "OKAY!";
} else {
echo "Nokay!";
}
}
}

Categories