I'm currently using a text file which contains a bunch of usernames, instead of the text file I want my script to run through a mysql column instead.
Is the line I'm having trouble with, I'm wondering if I could use the result of mysql query as the variable?
$name = file("/var/www/html/memberlist/memberlist.txt");
Here's my full code if needed
<?php
include 'dbopen.php';
function get_web_page($url) {
$options = array(
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HEADER => false,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_ENCODING => "",
CURLOPT_USERAGENT => "Highscores grabber v1.0",
CURLOPT_AUTOREFERER => true,
CURLOPT_CONNECTTIMEOUT => 120,
CURLOPT_TIMEOUT => 120,
CURLOPT_MAXREDIRS => 10
);
$ch = curl_init( $url );
curl_setopt_array( $ch, $options );
$content = curl_exec( $ch );
$err = curl_errno( $ch );
$errmsg = curl_error( $ch );
$header = curl_getinfo( $ch );
curl_close( $ch );
return $content;
}
function getStats($name)
{
$skills = array('Overall', 'Attack', 'Defence', 'Strength', 'Hitpoints', 'Ranged', 'Prayer', 'Magic', 'Cooking', 'Woodcutting', 'Fletching', 'Fishing', 'Firemaking', 'Crafting', 'Smithing', 'Mining', 'Herblore', 'Agility', 'Thieving', 'Slayer', 'Farming', 'Runecrafting', 'Hunter', 'Construction');
$hs = get_web_page("http://services.runescape.com/m=hiscore_oldschool/index_lite.ws?player=$name");
$out = Array();
$stats = explode("\n", $hs);
for($i = 0; $i<count($skills);$i++) {
$stat = explode(',', $stats[$i]);
$out[$skills[$i]] = Array();
$out[$skills[$i]]['rank'] = $stat[0];
$out[$skills[$i]]['level'] = $stat[1];
$out[$skills[$i]]['xp'] = $stat[2];
}
return $out;
}
$name = file("/var/www/html/memberlist/memberlist.txt");
for($j=0;isset($name[$j]);$j++)
{
$out[$j] = getStats($name[$j]);
}
if (!empty($out))
{
for($k=0;isset($out[$k]);$k++)
{
$hitpointsexp = $out[$k]['Hitpoints']['xp'];
$rangedexp = $out[$k]['Ranged']['xp'];
$magicexp = $out[$k]['Magic']['xp'];
$rsn = trim($name[$k]);
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
// Perform queries
$query= ("
INSERT INTO
gains (runescape_name, hitpoints_starting_exp, magic_starting_exp, range_starting_exp)
VALUES
('" . $rsn . "', '" . $hitpointsexp . "', '" . $magicexp . "', '" . $rangedexp . "')
ON DUPLICATE KEY UPDATE
hitpoints_starting_exp='$hitpointsexp', magic_starting_exp='$magicexp', range_starting_exp='$rangedexp'
");
$result = mysql_query($query);
}
}
?>
Related
I'm trying to set an get payment status API with a payment processor. Below is the code they provided me. There are some information in the $result variable that I want, what I don't understand is what type of variable is '$result' and how can I take certain data from it. printing the $result shows "Transaction ID is : xxxx status is ACCEPTED". What I basically want is to take only the transaction ID and store it in a variable.
function payFawry($ID)
{
$ticket = get_row("select * FROM `tickets` WHERE ID = '$ID' and canceled = 0");
$user = get_row("select * from users where ID = '$ticket[clientID]'");
$amount = $ticket[cost].".00";
$customerMobile = substr($user[phone],-11);
$description = "Ticket ".$ticket[ID];
$merchantCode = "CsdsadasdasdasdasdasdaJasdasd";
$merchantRefNum = $ticket[ID];
$customerProfileId = $ticket[clientID];
$paymentMethod = "PAYATFAWRY";
$cardToken = "";
$customerEmail = substr($user[email]);
$secureKey = "sadasdsadafdsfasfasdasdasdasd";
$signature = $merchantCode.$merchantRefNum.$customerProfileId.$paymentMethod.$amount.$cardToken.$secureKey;
$signature = hash('sha256', $signature);
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://atfawry.com/ECommerceWeb/Fawry/payments/charge',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => "{ \"merchantCode\":\"$merchantCode\", \"merchantRefNum\":\"$merchantRefNum\", \"customerProfileId\":\"$customerProfileId\", \"customerMobile\":\"$customerMobile\", \"customerEmail\":\"$customerEmail\", \"paymentMethod\":\"$paymentMethod\", \"cardToken\":\"$cardToken\", \"amount\":$amount, \"currencyCode\":\"EGP\", \"description\":\"$description\", \"paymentExpiry\":".strtotime('+3 hour')."077, \"chargeItems\":[ { \"itemId\":\"897fa8e81be26df25db592e81c31c\", \"description\":\"asdasd\", \"price\":$amount, \"quantity\":1 } ], \"signature\":\"$signature\" }",
CURLOPT_HTTPHEADER => array(
"Content-Type: application/json",
"cache-control: no-cache"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
$status = 1;
$response = json_decode ( $response , true ) ;
$referenceNumber = '<div style="font-size: 18px;line-height: 30px;margin-bottom: 9px;">Please proceed to any Fawry Retail (Kiosk, Supermarket) <br>Ask for Fawry Pay Service and enter you Reference Number: </div><div class="head-span" >'.$response[referenceNumber].'</div>';
$message = "برجاء استخدام رقم السداد $response[referenceNumber] لكود الخدمة 788 لدى فوري لتأكيد الحجز قم $ticket[ID]";
$new_password = encode_password($new_password) ;
send_sms($customerMobile ,$message);
$r = array("Status"=>$status,"Result"=>$referenceNumber,"referenceNumber"=>$response[referenceNumber],"Errors"=>"","NextStep"=>$NextStep);
return $r;
}
Returns 1 on success or 0 for non success
https://developer.fawrystaging.com/docs/server-apis/payment-notifications/get-payment-status-v2
I'm in big trouble that I have no idea what it can be.
I have an APP that has more than 100k users on the table, I happen to call the GCM service inside LOOP after about 1 minute presents this error message.
I have treated all the fields so as not to be NULL, I do not know what it can be!
Will it be timeout from ajax?
The call in GCM is as follows:
$url = 'https://android.googleapis.com/gcm/send';
$fields = array(
'data' => array(
"mensagem" => $message
),
'registration_ids' => $registatoin_ids
);
if (is_array($data)) {
foreach ($data as $key => $value) {
$fields['data'][$key] = $value;
}
}
$headers = array(
'Authorization: key=' . apiKey,
'Content-Type: application/json'
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
$result = curl_exec($ch);
if ($result === FALSE) {
die('Curl failed: ' . curl_error($ch));
}
curl_close($ch);
Loop to bring the database id-------------
for ($i = 0; $i < $num / 1000; $i++)
{
$query = $con->query("SELECT gcm_regid from registration where status ='S' and LENGTH(gcm_regid) = 152 and app_id=$Id_Aplicativo LIMIT $current_num,1000");
foreach($query as $data)
{
if (!is_null($data["gcm_regid"]))
{
$row[] = is_null($data["gcm_regid"]) ? " " : $data["gcm_regid"];
$cont = $cont + 1;
}
}
// print_r($row);
$pushStatus = send_notification($con, $row, $mensagem, array(
'titulo' => is_null($titulo) ? " " : $titulo, //$titulo,
'sub_mensagem' => is_null($sub_mensagem) ? " " : $sub_mensagem, //$sub_mensagem,
'content_mensagem' => is_null($content_mensagem) ? " " : $content_mensagem, //$content_mensagem,
'content_info' => is_null($content_info) ? " " : $content_info, //$content_info,
'url_imagem' => is_null($path . $nome_imagem) ? " " : $path . $nome_imagem, //$path.$nome_imagem,// Esse Path vem do arquivo Conect.php
'url_audio' => is_null($path_audio . $filenameAudio) ? " " : $path_audio . $filenameAudio, //$path_audio.$filenameAudio, // Esse Path vem do arquivo Conect.php
'tipo_notificacao' => is_null($TipoNotificacao) ? " " : $TipoNotificacao, //$TipoNotificacao
));
$row = null;
$current_num+= 1000;
}
404 Not Found Nginx/1.12.0
This is an auto promotion system (written in php) for a website, however it seems to give an error that I'm not familiar with. I replaced the website name with 'example' for privacy reasons.
<?php
$group_id = $_GET['groupId'];
$new_role_set_id = $_GET['newRoleSetId'];
$target_user_id = $_GET['targetUserId'];
$login_user = 'username=user&password=pass';
$file_path_rs = 'rs.txt';
$file_path_token = 'token.txt';
$current_rs = file_get_contents($file_path_rs);
$current_token = file_get_contents($file_path_token);
function getRS()
{
global $login_user, $file_path_rs;
$get_cookies = curl_init('https://www.example.com/newlogin');
curl_setopt_array($get_cookies,
array(
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HEADER => true,
CURLOPT_POST => true,
// CURLOPT_HTTPHEADER => array("Content-Length: " . strlen($login_user)),
CURLOPT_POSTFIELDS => $login_user
)
);
$rs = (preg_match('/(\.SECURITY=.*?);/', curl_exec($get_cookies), $matches) ? $matches[1] : '');
file_put_contents($file_path_rs, $rs, true);
curl_close($get_cookies);
return $rs;
}
function changeRank($rs, $token)
{
global $group_id, $new_role_set_id, $target_user_id, $file_path_token;
$promote_user = curl_init("http://www.example.com/groups/api/change-member- rank? groupId=$group_id&newRoleSetId=$new_role_set_id&targetUserId=$target_user_id");
curl_setopt_array($promote_user,
array(
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_HEADER => true,
CURLOPT_HTTPHEADER => array("Cookie: $rs", "X-CSRF-TOKEN: $token")
)
);
$resp = curl_exec($promote_user);
$resp_header_size = curl_getinfo($promote_user, CURLINFO_HEADER_SIZE);
$resp_header = substr($resp, 0, $resp_header_size);
$resp_body = substr($resp, $resp_header_size);
if (preg_match('/GuestData/', $resp_header)) {
$resp_body = changeRank( getRS(), $token );
} else if (preg_match('/Token Validation Failed/', $resp_header)) {
$new_token = (preg_match('/X-CSRF-TOKEN: (\S+)/', $resp_header, $matches) ? $matches[1] : '');
file_put_contents($file_path_token, $new_token, true);
$resp_body = changeRank( $rs, $new_token );
}
curl_close($promote_user);
return $resp_body;
}
echo changeRank($current_rs, $current_token);
When accessing the page I get the page error:
Bad Request - Invalid Content Length
HTTP Error 400. There is an invalid content length or chunk length in the request.
I'm not sure why this is happening, and I've tried just about everything, even switching hosts, but the issue still arises. What can I do to fix this?
<?php
require 'db.php';
function callInstagram($url)
{
$ch = curl_init();
curl_setopt_array($ch, array(
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_SSL_VERIFYHOST => 2
));
//catstagram start
$result = curl_exec($ch);
curl_close($ch);
return $result;
}
$tag = 'nypgraduation2014';
$client_id = "e4c623cb050444eeb7072e1a577da5b3";
$url = 'https://api.instagram.com/v1/tags/'.$tag.'/media/recent?client_id='.$client_id;
while (isset($url) && $url != '')
{
$inst_stream = callInstagram($url);
$results = json_decode($inst_stream, true);
foreach($results['data'] as $item)
{
$image_link = $item['images']['standard_resolution']['url'];
//$path_parts = pathinfo($image_link);
// save the file name in variable
//$image = ($path_parts['basename']);
//copy($image_link,"photos/" .$image);
mysql_query("INSERT INTO fypj131127cdb.instagramphoto(url) values('$image_link')");
// copy the file to you folder
}
$url = $result['pagination']['next_url'];
$image = "SELECT * FROM fypj131127cdb.instagramphoto ORDER BY ImageID ASC;";
$img_result=mysql_query($image);
$imageIndex = 0;
?>
Hi guys, I have trouble displaying all the instagram images with the hashtag #nypgraduation2014 using pagination. By using this codes, I don't know why I cannot display all the photos. As I am new to php and api, therefore I hope you guys can help me. Thanks!
So, here is my problem on login through steam id it creates an account on my website but it also decides on next login to skip an Auto Increment causing the next registered member to gain a ton of Auto Incremented member id's
<?php
require ("common.php");
class SteamSignIn
{
const STEAM_LOGIN = 'https://steamcommunity.com/openid/login';
public static function genUrl($returnTo = false, $useAmp = true)
{
$returnTo = (!$returnTo) ? (!empty($_SERVER['HTTPS']) ? 'https' : 'http') . '://' . $_SERVER['HTTP_HOST'] . $_SERVER['SCRIPT_NAME'] : $returnTo;
$params = array(
'openid.ns' => 'http://specs.openid.net/auth/2.0',
'openid.mode' => 'checkid_setup',
'openid.return_to' => $returnTo,
'openid.realm' => (!empty($_SERVER['HTTPS']) ? 'https' : 'http') . '://' . $_SERVER['HTTP_HOST'],
'openid.identity' => 'http://specs.openid.net/auth/2.0/identifier_select',
'openid.claimed_id' => 'http://specs.openid.net/auth/2.0/identifier_select',
);
$sep = ($useAmp) ? '&' : '&';
return self::STEAM_LOGIN . '?' . http_build_query($params, '', $sep);
}
public static function validate()
{
$params = array(
'openid.assoc_handle' => $_GET['openid_assoc_handle'],
'openid.signed' => $_GET['openid_signed'],
'openid.sig' => $_GET['openid_sig'],
'openid.ns' => 'http://specs.openid.net/auth/2.0',
);
$signed = explode(',', $_GET['openid_signed']);
foreach($signed as $item)
{
$val = $_GET['openid_' . str_replace('.', '_', $item)];
$params['openid.' . $item] = get_magic_quotes_gpc() ? stripslashes($val) : $val;
}
$params['openid.mode'] = 'check_authentication';
$data = http_build_query($params);
$context = stream_context_create(array(
'http' => array(
'method' => 'POST',
'header' =>
"Accept-language: en\r\n".
"Content-type: application/x-www-form-urlencoded\r\n" .
"Content-Length: " . strlen($data) . "\r\n",
'content' => $data,
),
));
$result = file_get_contents(self::STEAM_LOGIN, false, $context);
preg_match("#^http://steamcommunity.com/openid/id/([0-9]{17,25})#", $_GET['openid_claimed_id'], $matches);
$steamID64 = is_numeric($matches[1]) ? $matches[1] : 0;
return preg_match("#is_valid\s*:\s*true#i", $result) == 1 ? $steamID64 : '';
}
}
$steam_login_verify = SteamSignIn::validate();
if(!empty($steam_login_verify))
{
// Grab Data From Steam API
$json = file_get_contents('http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=' . $sapik . '&steamids='. $steam_login_verify .'&format=json');
//Decode Data From Steam API
$data = json_decode($json);
foreach($data->response->players as $player)
{
$query = "INSERT INTO steam (steamid, personaname, profileurl, avatar, avatarmedium, avatarfull ) VALUES ( :steamid, :personaname, :profileurl, :avatar, :avatarmedium, :avatarfull) ";
$query_params = array(
':steamid' => $player->steamid,
':personaname' => $player->personaname,
':profileurl' => $player->profileurl,
':avatar' => $player->avatar,
':avatarmedium' => $player->avatarmedium,
':avatarfull' => $player->avatarfull,
);
}
try
{
$stmt = $db->prepare($query);
$result = $stmt->execute($query_params);
}
catch(PDOException $ex)
{
switch( $ex->errorInfo[1] )
{
case 1062:
$ps = $db->prepare("SELECT * FROM `steam` WHERE steamid = :sid");
$ps->bindParam(':sid', $steam_login_verify);
$ps->execute();
$ps->setFetchMode(PDO::FETCH_ASSOC);
foreach ($ps as $row)
{
$_SESSION['sid'] = $row['steamid'];
}
header('Location:'.$basedir);
die('redirecting to'.$basedir);
;
}
}
$ps = $db->prepare("SELECT * FROM `steam` WHERE steamid = :sid");
$ps->bindParam(':sid', $steam_login_verify);
$ps->execute();
$ps->setFetchMode(PDO::FETCH_ASSOC);
foreach ($ps as $row)
{
$_SESSION['sid'] = $row['steamid'];
}
header('Location:'.$basedir);
die('redirecting to'.$basedir);
} else {
$steam_sign_in_url = SteamSignIn::genUrl();
}