Getting this error
[Tue Aug 18 14:41:57.614006 2015] [:error] [pid 21389] [client 67.90.138.68:5794] PHP Warning: file_get_contents(http://steamcommunity.com/market/priceoverview/?appid=295110¤cy=1&market_hash_name=BR: Vigilante Crate): failed to open stream: HTTP request failed! HTTP/1.0 500 Internal Server Error\r\n
<?php
foreach($json2['rgDescriptions'] as $i){
$item = $i['market_name'];
$icon = $i['icon_url'];
$fetchdata = 'http://steamcommunity.com/market/priceoverview/?appid=295110¤cy=1&market_hash_name=' . $item;
$grab = file_get_contents($fetchdata);
$id = json_decode($grab, true);
echo '<img src="'. $imgurlbase . $icon . '/64fx64f">' . '<a class="btn btn-primary btn-lg" href="#" role="button">' . $item . '</a>'. '<a class="btn btn-primary btn-lg" href="#" role="button">'. $id['lowest_price'].'</a>'.'<br>';
}
For some reason the & in the base url is getting passed as '& amp;' each time in the url and not as &
I am not the best with php, yet nothing I am searching for is coming up with why. Does it have to do with the json_decode? That is my only guess.
you need to encode the string:
$fetchdata = 'http://steamcommunity.com/market/priceoverview/?appid=295110¤cy=1&market_hash_name=' . urlencode($item);
works for me:
php > $fetchdata ='http://steamcommunity.com/market/priceoverview/?appid=295110¤cy=1&market_hash_name='.urlencode('BR: Vigilante Crate');
php > $grab = file_get_contents($fetchdata);
php > print_r(json_decode($grab));
stdClass Object
(
[success] => 1
[lowest_price] => $0.07
[volume] => 4,994
[median_price] => $0.07
)
Related
I am writing this in shell;
sudo tail -100 /var/log/apache2/error.log
And, I saw this;
......
[Sun Feb 14 09:42:06.873076 2021] [php7:warn] [pid 1968] [client 82.222.237.83:36955] PHP Warning: ltrim() expects parameter 1 to be string, object given in /var/www/html/wp-includes/formatting.php on line 4314
[Sun Feb 14 09:42:06.873149 2021] [php7:warn] [pid 1968] [client 82.222.237.83:36955] PHP Warning: ltrim() expects parameter 1 to be string, object given in /var/www/html/wp-includes/formatting.php on line 4314
...
I'm going to the relevant code. --> /var/www/html/wp-includes/formatting.php on line 4314
function esc_url( $url, $protocols = null, $_context = 'display' ) {
$original_url = $url;
if ( '' === $url ) {
return $url;
}
$url = str_replace( ' ', '%20', ltrim( $url ) );
$url = preg_replace( '|[^a-z0-9-~+_.?#=!&;,/:%#$\|*\'()\[\]\\x80-\\xff]|i', '', $url );
if ( '' === $url ) {
return $url;
}
if ( 0 !== stripos( $url, 'mailto:' ) ) {
$strip = array( '%0d', '%0a', '%0D', '%0A' );
$url = _deep_replace( $strip, $url );
}
$url = str_replace( ';//', '://', $url );
on line 4314;
$url = str_replace( ' ', '%20', ltrim( $url ) );
I did not understand. My error page is full of this. I could not figure out despite my research. Can you help me?
Note: Ubuntu 20.04, Wordpress
Healthy days,
Best regards.
The function esc_url() is called with a $url that is object rather a string. You can use gettype() or print_r() to confirm. debug_backtrace() might be useful to figure out where you are making those calls from.
My code should convert "defindex" from array_inv into "item_name" from array_schema:
<?php
$apikey = "X";
$steamid = $steamprofile['steamid'];
$url_inv = "http://api.steampowered.com/IEconItems_730/GetPlayerItems/v0001/?language=en?key=". $apikey . "&steamid=" . $steamid . "&format=json";
$url_schema = "http://git.optf2.com/schema-tracking/plain/Counter%20Strike%20Global%20Offensive%20Schema?h=counterstrikeglobaloffensive";
$array_inv_raw = file_get_contents($url_inv);
$array_schema_raw = file_get_contents($url_schema);
$array_inv = json_decode($array_inv_raw,true);
$array_schema = json_decode($array_schema_raw,true);
foreach($array_inv['result']['items'] as $item){
foreach($array_schema['result']['items'] as $schemaItem){
if($item['defindex'] == $schemaItem['defindex']){
echo $schemaItem['item_name'].'<br />';
break;
}
}
}
?>
But it's resulting in these errors:
Warning:
file_get_contents(http://api.steampowered.com/IEconItems_730/GetPlayerItems/v0001/?language=en?key=x&steamid=76561198037897388&format=json):
failed to open stream: HTTP request failed! HTTP/1.1 403 Forbidden in
/home/kartm/public_html/scripts/inv.php on line 6
Warning: Invalid argument supplied for foreach() in
/home/kartm/public_html/scripts/inv.php on line 12
The urls:
array_inv
array_schema
I can't find any mistakes. Can you tell me what's wrong with this code?
These errors were caused by a typo in a url:
http://api.steampowered.com/IEconItems_730/GetPlayerItems/v0001/?language=en?key=x&steamid=76561198037897388&format=json
It should have been & key=x instead of ?key=x.
file_get_contents couldn't fetch the url, thus the foreach had an invalid, empty argument.
My php code have been working fine. And suddenly i got very strange string in response data.
Every response data is like below.where is "87,0" and"3e,0" come from? How can i get rid of them?(They appears before and after every response data.)
HTTP/1.1 200 OK
Date: Fri, 14 Nov 2014 01:57:40 GMT
Server: Apache
X-Powered-By: PHP/5.4.34
Connection: close
Transfer-Encoding: chunked
Content-Type: text/html
87
a:1:{i:0;s:116:"http://www.nytimes.com/2014/09/15/sports/basketball/united-states-wins-fiba-world-cup-title-in-a-rout-of-serbia.html";}
0
HTTP/1.1 200 OK
Date: Fri, 14 Nov 2014 01:57:40 GMT
Server: Apache
X-Powered-By: PHP/5.4.34
Connection: close
Transfer-Encoding: chunked
Content-Type: text/html
3e
a:1:{i:0;s:44:"http://www.bbc.com/news/in-pictures-29204063";}
0
foreach($template_arr as $tkey => $template)
{
$keyword = self::getKeyword($template, $typename);
$keyword = urlencode($typename);//encode because it is going to be send through url
$urlPre = self::getURLPre('news');
$urlrule = self::getURLRule($template); //actually it is used in both siteSearch and urlrule,but urlrule seems unnecessary
$s = stream_socket_client("$sochost:$socportno", $errno, $errstr, $soctimeout, STREAM_CLIENT_ASYNC_CONNECT | STREAM_CLIENT_CONNECT);
if ($s)
{
$sockets[$template] = $s;
$out = "GET /DataAC/Search/Search_Bridge_G.php?keyword=$keyword&resultSize=$resultSize&urlPre=$urlPre&urlrule=$urlrule&template=$template";
$out.= " HTTP/1.1\r\n";
$out.= "Connection: Close\r\n";
$out.= "Host:$sochost\r\n\r\n";
fwrite($s, $out);
}
else
{
echo "$errstr ($errno) ,open sock on search keyword # $keyword on template # $tempalte erro when open search bridge.<br/>\n";
}
}
while (count($sockets))
{
$read = $sockets;
$w = null;
$e = null;
stream_select($read, $w, $e, $soctimeout);
if (count($read))
{
/* stream_select generally shuffles $read, so we need to
compute from which socket(s) we're reading. */
foreach($read as $r)
{
$template = array_search($r, $sockets);
$data = fread($r, $convenient_read_block);
// A socket is readable either because it has
// data to read, OR because it's at EOF.
if (strlen($data) == 0)
{
//echo "Template " . $template . " closes at " . date('h:i:s') . "</br>";
$responseData = $result[$template];
echo "!!!!!!!!!!!!!!!$responseData!!!!!!!!!!!!!!!";
$responseArray=unserialize(substr($responseData,strpos($responseData,"\r\n\r\n")+4)); //get serialize array from respose data and unserialize it ,"+4" means we don't need \r\n\r\n
//var_dump($responseArray);
$urlarr = $responseArray;
// assemble result array start
if (!empty($urlarr))
{
$template_url_arr[$template] = $urlarr[0];
$timenow = date('Y-m-d H:i:s', time());
echo "</br>######### Machine search : keyword:#" . $typename . " target url:" . $urlarr[0] . " timestamp: $timenow" . "#########</br>";
}
else
{
echo "</br> ######### Template url arr empty when query keyword #" . $keyword . " under template #" . $template . " #########</br>";
}
// assemble result array end
fclose($r);
unset($sockets[$template]);
}
else
{
if(!isset($result[$template]))//init the array element or there will be a warning
$result[$template]= "";
$result[$template].= $data;
}
}
}
else
{
/* A time-out means that *all* streams have failed
to receive a response. */
echo "Time-out!\n";
break;
}
}
script:Search_Bridge_G.php
require_once '../../global.php';
//require_once('UTIL/MyFileUtil.php');
//require_once('UTIL/MyDocUtil.php');
require_once 'DataAC/Search/GetGSearchLink.php';
error_reporting(E_ALL);
$keyword=$_GET['keyword'];
$keyword=preg_replace('/\s+/', '%20', trim($keyword)); //replace ' ' with %20
$resultSize=$_GET['resultSize'];
$urlPre=$_GET['urlPre'];
$urlrule=$_GET['urlrule'];
$template=$_GET['template'];
$ant = new \DataGenerator\GetLinkG\GetGSearchLink($keyword,$resultSize, $urlPre,$urlrule);
$urlarr = $ant->getFilteredURL($template);
/*
echo "</br>key:".$keyword."</br>";
echo "</br>rsize:".$resultSize."</br>";
echo "</br>urlpre:".$urlPre."</br>";
echo "</br>urlrule:".$urlrule."</br>";
echo "</br>templa:".$template."</br>";
*/
//var_dump($urlarr);
echo serialize($urlarr);
When an HTTP server cannot determine the Content-Length: in advance, for instance when the output is produced by a dynamic script as opposed to a static file, it will send the output in chunks (as indicated by the Transfer-Encoding: chunked header). Each chunk is prefixed by length expressed in hexadecimal digits. Those are the "strange strings" that you see. The exact details can be found in:
RFC 7230: Hypertext Transfer Protocol (HTTP/1.1): Message Syntax and Routing
I'm having trouble using the facebook api to post a photo to a page's wall. If I upload the file via php and use $_FILES[]["tmp_name"] as my $filelocation it works fine. However if I change $filelocation to a local filepath ( /tmp/1351750505-24d.jpg ) it doesn't work.
I've given my /tmp dir 777 and made sure my file is 777 as well to eliminate any permission issues. I've also used multiple files to make sure its not just an issue with one file.
The only other thought I have is that this could be a random setting in php.ini, but I didn't see anything glaring at me.
Error log:
[Thu Nov 01 06:52:13 2012] [error] [client 66.x.x.x] {"error":{"message":"(#1) An unknown error occurred","type":"OAuthException","code":1}}, referer: http://origin.example.com/adder/index.php
[Thu Nov 01 06:52:13 2012] [error] [client 66.x.x.x] $filelocation = /tmp/1351752730-24e.jpg, referer: http://origin.example.com/adder/index.php
[ec2-user#ip-10-x-x-x adder]$ ll /tmp/1351750505-24d.jpg
-rwxrwxrwx 1 apache apache 331 Nov 1 06:15 /tmp/1351750505-24d.jpg
$facebook->setFileUploadSupport(true);
$post_id = "";
try
{
$post_id = $facebook->api("/$page_id/photos", 'POST',
array(
'source' => '#' . $filelocation,
'message' => $name
));
error_log("\$filelocation = " . $filelocation);
} catch (FacebookApiException $e)
{
$result = $e->getResult();
error_log(json_encode($result));
$post_id["id"] = "FAIL!";
error_log("\$filelocation = " . $filelocation);
}
When I set $filelocation to /tmp/somefile.jpg it posts the local path/file fine. I notice one difference between your code and my code: I include the page access token in the POST call:
$local_path = '/tmp/water96x96.jpg';
$args = array(
'access_token' => $page_info['access_token'],
'message' => 'Testing photo upload via SDK!',
'source' => '#'.$local_path,
);
$post_id = $facebook->api('/'.$page_id.'/photos', 'post', $args);
To get the page access token, I do:
$page_info = $facebook->api('/'.$page_id.'?fields=access_token');
with a logged in user who is an admin of the page with manage_pages permission.
i was programming a mail templatingsystem. The user should be able to use markers in there, they will be replaced by the actual data. The problem ist, my function to replace the markers works just fine, but i need to do a recursiv call of that function, that will only run once, and this is what i came up with:
public function replace_placeholders($content, $recipient, $settings, $interface, $recommendation, $format, $recursion = false) {
$content = $this->replace_ph('briefanrede' , $recipient['id'] , $content);
$content = $this->replace_ph('anrede' , $recipient['title'] , $content);
$content = $this->replace_ph('email' , $recipient['email'] , $content);
$content = $this->replace_ph('kundennummer' , $recipient['kdnumber'] , $content);
$content = $this->replace_ph('briefanrede' , $recipient['briefanrede'] , $content);
if($recipient['title'] == $settings['anrede_w'] || $recipient['title'] == $settings['anrede_m']) {
$content = $this->replace_ph('vorname' , $recipient['forename'] , $content);
$content = $this->replace_ph('nachname' , $recipient['surename'] , $content);
} else {
$content = $this->replace_ph('vorname' , "" , $content, true);
$content = $this->replace_ph('nachname' , "" , $content, true);
}
$content = $this->replace_salutation($recipient, $settings, $content);
//Recommendation
if($this->need_replacement($content, 'weiterempfehlung') === false && $recursion === false) {
if($recommendation['own_page'] == 1) {
$baseurl = $recommendation['location'];
} else {
$baseurl = $recommendation['link'];
}
$pattern = ($format == "html") ? '%s' : '%s';
$url = $this->replace_placeholders($baseurl, $recipient, $settings, $interface, $recommendation, true);
$content = $this->replace_ph('weiterempfehlung' , (($format == "html") ? sprintf($pattern, $url, $settings['text_weiterempfehlung']): sprinf($pattern, $url)), $content);
}
return $content;
}
The recursiv call in this line
$url = $this->replace_placeholders($baseurl, $recipient, $settings, $interface, $recommendation, true);
is causing a 500 internal server error. I dont know why, because i think that i limited the recursion to run once. Can you help me out?
Sorry for my bad english i try hard to write clear sentences.
//EDIT:
Apache log:
[Wed May 30 15:31:56 2012] [warn] [client xx.xxx.xx.xxx] (104)Connection reset by peer: mod_fcgid: error reading data from FastCGI server
[Wed May 30 15:31:56 2012] [warn] [client xx.xxx.xx.xxx] (104)Connection reset by peer: mod_fcgid: ap_pass_brigade failed in handle_request_ipc function
[Wed May 30 15:31:56 2012] [error] [client xx.xxx.xx.xxx] File does not exist: /var/www/web80/html/web80-newsletter/favicon.ico
[Wed May 30 15:31:58 2012] [error] mod_fcgid: process /var/www/php-fcgi/web80.php53/php-fcgi(21975) exit(communication error), get unexpected signal 11
the php errorlog is empty.
It would seem you miss one argument in your recursive call, making the $recursive = false continue being false all the time, which in turn makes your if statement
if($this->need_replacement($content, 'weiterempfehlung') === false && $recursion === false)
always return true.
Try adding one last variable to your recursive call instead and you should be able to properly execute your script, ie:
$url = $this->replace_placeholders($baseurl, $recipient, $settings, $interface,
$recommendation, true, true);
^ added one true
What i think you want to add instead of the first true is $format.
Signal 11 is SIGSEGV, i.e. the process crashed due to a bad memory access (such as dereferencing a NULL pointer or accessing memory it was not supposed to access).
This is nothing a PHP script should be causing, so you should first upgrade to the most recent stable PHP version and if it still happens reduce your script as much as possible (remove everything that can be removed while the crash still happens) and then report it as a PHP bug.