PHP can't read/receive response - php

So what I am trying to do is receiving data about a player from the Steam API.
Basically, a player logs in via the Steam website and then gets redirected to a page of my website where data about the player is registered into the database.
It seems that the data about the player (which is being retrieved from the Steam API) is null (it cant be retrieved)
When I try to access the API in the browser, it works just fine.
Here is the code for registering the data:
$url = "http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX&steamids=". $matches[1];
$json_object = file_get_contents($url);
$json_decoded = json_decode($json_object);
foreach ($json_decoded->response->players as $player) {
$steamid = $player->steamid;
$name = $player->personaname;
$avatar = $player->avatar;
}
$hash = md5($steamid . time() . rand(1, 50));
$sql = $db->query("SELECT * FROM `users` WHERE `steamid` = '" . $steamid . "'");
$row = $sql->fetchAll(PDO::FETCH_ASSOC);
if (count($row) == 0) {
$db->exec("INSERT INTO `users` (`hash`, `steamid`, `name`, `avatar`) VALUES ('" . $hash . "', '" . $steamid . "', " . $db->quote($name) . ", '" . $avatar . "')");
} else {
$db->exec("UPDATE `users` SET `hash` = '" . $hash . "', `name` = " . $db->quote($name) . ", `avatar` = '" . $avatar . "' WHERE `steamid` = '" . $steamid . "'");
}
If you want to try the API out your self, copy the $url and replace $matches[1] with this steam id: 76561198117114460
Thanks in advance,
Guus Huizen

Related

mysql update query wont execute

i have two update queries to update mysql db of the system.problem is my second update query works but my first one doesn't execute at all.
cant figure out whats going on...any help would be great
here is my php code.
$dob = $_POST["dob"];
$name = $_POST["name"];
$mob = $_POST["mobileNo"];
$home = $_POST["homeNO"];
$files = $_FILES["filep"]["name"];
echo $files;
$folder = "images/";
$uid = $_SESSION["Uid"];
if($_FILES["filep"]["error"] == 4) {
echo "no file selected";
}
move_uploaded_file($_FILES["filep"]["tmp_name"] , "$folder".$_FILES["filep"]["name"]);
$result = mysqli_query($con,"UPDATE User SET DOB = '" . $uid . "', MOBNO = '" . $mob . "', HOMENO = '" . $home . "',DOB = '" . $dob . "',IMAGE_URL = '" . $files . "' WHERE UID='" . $uid . "'");
$result = mysqli_query($con,"UPDATE User_Credentials SET NAME = '" . $name . "' WHERE CID='" . $uid . "'");
i have checked all the $name,$mob etc variables and value are passing without any problem..

Could not find what's wrong in sql set values

I have the following SQL.
$sql_shells = "UPDATE `shells` SET `situation` = 'sold' WHERE `id` = '" . $id . "'";
$conn->query($sql_shells);
I updated the rows with column named buytime and another one called buyer so it would be like this:
$sql_shells = "UPDATE `shells` SET `buyer`= " . $buyer . ", `buytime`= " . $trn_date . " , `situation` = 'sold' WHERE `id` = '" . $id . "'";
$conn->query($sql_shells);
It's not updating.
`$trn_date = $trn_date = date("Y-m-d H:i:s");
and
$buyer = $_SESSION['username'];
Error log is empty.
Another SQL update doesn't have constant values and works fine
$sql_users = "UPDATE `users` SET `amount`= " . $newAmount . ", `gain`= " . $newgain . " WHERE `username` = '" . $buyer . "'";
I tried echoing the SQL query that's not working, this is what I get when I run it.
try to remove ` caracter and i think buytime and buyer should add ' caracter and remove it from id if is int type:
$sql_shells = "UPDATE shells SET buyer= '" . $buyer . "', buytime= '" . $trn_date . "' , situation = 'sold' WHERE id = " . $id ;
$conn->query($sql_shells);

OpenID duplicate results in database

I am trying to make a webiste with Yahoo OpenID.
Everything works fine until I log out and then log in again.
In my sql database I get duplicated results. Only the hash is changed. It seems that $sql = $db->query("SELECT * FROM users WHERE steamid = '" . $steamid . "'"); can't find any users with the steamid to it creates a new entry in the db.
I tried this with Steam too and it's working. With Yahoo, I get duplicate results with my email adress(here $steamid), and name(here $name). The hashes are different.
case 'login':
include 'openid.php';
try
{
$openid = new LightOpenID('http://'.$_SERVER['SERVER_NAME'].'/');
if (!$openid->mode) {
$openid->identity = 'https://me.yahoo.com/a/6eqERecwyZfHsDm6VBa7H2uWNu3W5.UvCw--'; //http://steamcommunity.com/openid/
$openid->required = array(
'contact/email',
'namePerson',
);
header('Location: '.$openid->authUrl());
} elseif ($openid->mode == 'cancel') {
echo '';
} else {
if ($openid->validate()) {
//$id = $openid->identity;
//$ptn = "/^http:\/\/steamcommunity\.com\/openid\/id\/(7[0-9]{15,25}+)$/";
//preg_match($ptn, $id, $matches);
//$url = "http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=78DC279A43117B222DDEE0FCCCAD38FD&steamids=$matches[1]";
//$json_object = file_get_contents($url);
//$json_decoded = json_decode($json_object);
//foreach ($json_decoded->response->players as $player) {
$data = $openid->getAttributes();
$steamid = $data['contact/email'];
$name = $data['namePerson'];
//$avatar = $player->avatar;
//}
$hash = md5($steamid . time() . rand(1, 50));
$sql = $db->query("SELECT * FROM `users` WHERE `steamid` = '" . $steamid . "'");
$row = $sql->fetchAll(PDO::FETCH_ASSOC);
if (count($row) == 0) {
$db->exec("INSERT INTO `users` (`hash`, `steamid`, `name`) VALUES ('" . $hash . "', '" . $steamid . "', " . $db->quote($name) . ")");
} else {
$db->exec("UPDATE `users` SET `hash` = '" . $hash . "', `name` = " . $db->quote($name) . "' WHERE `steamid` = '" . $steamid . "'");
}
setcookie('hash', $hash, time() + 3600 * 24 * 7, '/');
header('Location: http://45.55.69.74/');
}
}
} catch (ErrorException $e) {
exit($e->getMessage());
}
break;
The problem was that the steamid length in the database was smaller. Everytime it checked if the entire steamid is the same as the smaller steamid.

Internal server error 500 when try to insert huge amount of data?

i had a problem. I try to insert huge amount of data ~400K rows.
Somewhere in middle of execution - i get error
"internal server error 500".
Can you help me to solve it? (Laravel 5.1, IIS)
public function updateForClients(Request $request) {
Debugbar::disable();
if($request->has('sku_list') && $request->has('clients')) {
DB::disableQueryLog();
$sku_list = array_map('trim', explode('|', $request->get('sku_list')));
$clients = array_map('trim', explode('|', $request->get('clients')));
$text_color_date = Carbon::parse($request->get('text_color_date'));
$text_color = $request->get('color');
$sql = [];
$today = Carbon::now()->format('Y-m-d H:i:s');
foreach($clients as $client) {
$sql[$client] = "BEGIN TRANSACTION ";
$sql[$client] .= "DELETE FROM eltk.dbo.system_products_meta_client WHERE client_id = '" . $client . "' AND sku IN ('". implode("', '", $sku_list) ."') ";
foreach($sku_list as $sku) {
$sql[$client] .= "INSERT INTO eltk.dbo.system_products_meta_client VALUES ('" . $sku . "', '" . $client . "', '" . $text_color . "', '" . $text_color_date . "', '" . $today ."', '" . $today ."') ";
}
$sql[$client] .= "COMMIT TRANSACTION GO";
}
foreach($sql as $query) {
DB::statement($query);
}
return redirect()->route('product.index')->with('form_success', true)->with('form_message', 'Information saved successfully!');
}
return redirect()->back();
}

Does not work perfectly for Online User in WordPress

I am making a classified website in wordpress with classipress theme,
http://www.mohibsalahuddin.com/client/ads/test-ad/
for showing author is online or offline on ad page, i wrote the following code, but it does not work if two users registered at a time... If registered user wants to see another registered user's status it always shows offline...
I though may be i missed session start thing do i have to write it? Kindly help me in this
I write the code below
First I create the table in MYSQL
CREATE TABLE wordpress_users_online` (
user_id int(11) default NULL,
full_name varchar(64) NOT NULL default '',
session_id varchar(128) NOT NULL default '',
ip_address varchar(15) NOT NULL default '',
time_entry varchar(14) NOT NULL default '',
time_last_click varchar(14) NOT NULL default '',
last_page_url varchar(255) NOT NULL default ''
) ENGINE=MyISAM;`
THEN I WRITE THE FILE wordpress_users_online.php with following code
<?php
define('TABLE_USERS', 'wordpress_users');
define('TABLE_USER_ONLINE', 'wordpress_users_online');
function update_user_online() {
//global $user_id;
global $current_user;
get_currentuserinfo();
if ($current_user->ID && $current_user->user_login) {
$wo_user_id = $current_user->ID;
$wo_full_name = $user['user_nicename'];
} else {
$wo_user_id = '';
$wo_full_name = 'Guest';
}
$wo_session_id = session_id();
$wo_ip_address = getenv('REMOTE_ADDR');
$wo_last_page_url = getenv('REQUEST_URI');
$current_time = time();
$xx_mins_ago = ($current_time - 300);
// remove entries that have expired
mysql_query("delete from " . TABLE_USER_ONLINE . " where time_last_click < '" . $xx_mins_ago . "'");
$stored_user_query = mysql_query("select count(*) as count from " . TABLE_USER_ONLINE . " where session_id = '" . mysql_escape_string($wo_session_id) . "'");
$stored_user = mysql_fetch_array($stored_user_query);
if ($stored_user['count'] > 0) {
mysql_query("update " . TABLE_USER_ONLINE . " set user_id = '" . (int)$wo_user_id . "', full_name = '" . mysql_escape_string($wo_full_name) . "', ip_address = '" . mysql_escape_string($wo_ip_address) . "', time_last_click = '" . mysql_escape_string($current_time) . "', last_page_url = '" . mysql_escape_string($wo_last_page_url) . "' where session_id = '" . mysql_escape_string($wo_session_id) . "'");
} else {
mysql_query("insert into " . TABLE_USER_ONLINE . " (user_id, full_name, session_id, ip_address, time_entry, time_last_click, last_page_url) values ('" . (int)$wo_user_id . "', '" . mysql_escape_string($wo_full_name) . "', '" . mysql_escape_string($wo_session_id) . "', '" . mysql_escape_string($wo_ip_address) . "', '" . mysql_escape_string($current_time) . "', '" . mysql_escape_string($current_time) . "', '" . mysql_escape_string($wo_last_page_url) . "')");
}
}
function is_online($user_id) {
$stored_user_query = mysql_query("select user_id from ".TABLE_USER_ONLINE." where user_id = '" . mysql_escape_string($user_id) . "'");
$stored_user = mysql_fetch_array($stored_user_query);
if(isset($stored_user['user_id'])){
$online = '<img src="http://www.mohibsalahuddin.com/client/wp-content/themes/classipress-313/images/online.png" border="0" /> Online';
echo $online;
}
else {
$online = '<img src="http://www.mohibsalahuddin.com/client/wp-content/themes/classipress-313/images/offline.png" border="0" /> Offline';
echo $online;
}
return $online;
}
?>
There's actually a wordpress plugin for this already...
--Edit--
http://wordpress.org/extend/plugins/wp-useronline/
Sorry the following was the original suggestions but they were the wrong links:
http://wordpress.org/extend/plugins/who-is-online/faq/
http://wordpress.org/extend/plugins/wassup/
Remember, don't re-invent the wheel unless you're going to make it hover too.

Categories