Jump to content

File Get Contents Http 404 Error


shadysaiyan

Recommended Posts

I'm in the process of trying to make my own PS3 trophycard. This is what i've got so far and im pretty sure it should run properly, but when i run it, i get this error and i don't know exactly what to do about it.

 

I'd appreciate the help, i always come here for my PHP problems :D

 

Error:

Warning: file_get_contents(http://profiles.us.playstation.com/playstation/psn/profiles/shadysaiyanz) [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found in /home/content/s/h/a/shadysaiyan/html/trophycard/trophycard.php on line 9

 

Live for reference

 

My code:

<?php

$username = "shadysaiyanz";
$url = "http://profiles.us.playstation.com/playstation/psn/profiles/$username";
$path = "users/cache/$username.png";

$buffer = file_get_contents ( $url );
if (! ($buffer))
die ( "Could not retrieve PSN information" );

preg_match_all ( "/<div id='id-handle'>([^<]*)<\/div>/i", $buffer, $psnid );
preg_match_all ( "/<div id='leveltext'>([^<]*)<\/div>/i", $buffer, $psnlevel );
preg_match_all ( "/<div id='text'>([^<]*)<\/div>/i", $buffer, $psntrophies );
preg_match_all ( "/<div class='text bronze'>([^<]*) (trophies?)<\/div>/i", $buffer, $psnbronze );
preg_match_all ( "/<div class='text silver'>([^<]*) (trophies?)<\/div>/i", $buffer, $psnsilver );
preg_match_all ( "/<div class='text gold'>([^<]*) (trophies?)<\/div>/i", $buffer, $psngold );
preg_match_all ( "/<div class='text platinum'>([^<]*) (trophies?)<\/div>/i", $buffer, $psnplatinum );

$psn = $psnid [1];
$level = $psnlevel [1];
$trophies = $psntrophies [1];
$bronze = $psnbronze [1];
$silver = $psnsilver [1];
$gold = $psngold [1];
$platinum = $psnplatinum [1];

for($i = 0; $i < count ( $psn ); $i ++) {

$psn [$i] = textlimit ( $psn [$i], 25 );

$trophies [$i] = preg_replace ( '/ Bronze|Silver|Gold|Platinum$/', '', $trophies [$i] );

}

$background = "themes/trophycard_1.png";
$imagename = "$username.png";
$imgpath = $_SERVER ['DOCUMENT_ROOT'] . "/trophycard/users/$username.png";
$im = imagecreatefrompng ( $background );
$black = imagecolorallocate ( $im, 0, 0, 0 );
$white = ImageColorAllocate ( $im, 255, 255, 255 );
$orange = ImageColorAllocate ( $im, 255, 180, 0 );
$red = ImageColorAllocate ( $im, 255, 0, 0 );
$font = 'fonts/visitor2.ttf';

imagettftext ( $im, 10, 0, 180, 35, $white, $font, $psn [0] );

header ( "Content-type: image/png" );
imagepng ( $im, $path );

?>

Link to comment
Share on other sites

Use cURL, you can use this function the same way you use file_get_contents.

 

function getPage($url, $timeout=25, $header=null){
$curl = curl_init();
curl_setopt ($curl, CURLOPT_URL, $url);
curl_setopt ($curl, CURLOPT_CONNECTTIMEOUT, $timeout);
curl_setopt ($curl, CURLOPT_USERAGENT, sprintf("Mozilla/%d.0",rand(4,5)));
curl_setopt ($curl, CURLOPT_HEADER, (int)$header);
curl_setopt ($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($curl, CURLOPT_SSL_VERIFYPEER, 0);
$html = curl_exec ($curl);
curl_close ($curl);
return $html;
}

Link to comment
Share on other sites

k, it runs now, but the text still doesn't show up. :( Did i put it in right?

 

<?php

function getPage($url, $timeout=25, $header=null){
$curl = curl_init();
curl_setopt ($curl, CURLOPT_URL, $url);
curl_setopt ($curl, CURLOPT_CONNECTTIMEOUT, $timeout);
curl_setopt ($curl, CURLOPT_USERAGENT, sprintf("Mozilla/%d.0",rand(4,5)));
curl_setopt ($curl, CURLOPT_HEADER, (int)$header);
curl_setopt ($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($curl, CURLOPT_SSL_VERIFYPEER, 0);
$html = curl_exec ($curl);
curl_close ($curl);
return $html;
}

$username = "shadysaiyanz";
$url = "http://profiles.us.playstation.com/playstation/psn/profiles/$username";
$path = "users/cache/$username.png";

$buffer = getPage($url);

if (! ($buffer))
die ( "Could not retrieve PSN information" );

$buffer = strtr ( $buffer, array ("\n" => '', "\r" => '', "\t" => '', '<' => '<', '>' => '>', '&' 

=> '&', '"' => '"', ''' => "'" ) );

preg_match_all ( "/<div id='id-handle'>([^<]*)<\/div>/i", $buffer, $psnid );
preg_match_all ( "/<div id='leveltext'>([^<]*)<\/div>/i", $buffer, $psnlevel );
preg_match_all ( "/<div id='text'>([^<]*)<\/div>/i", $buffer, $psntrophies );
preg_match_all ( "/<div class='text bronze'>([^<]*) (trophies?)<\/div>/i", $buffer, $psnbronze );
preg_match_all ( "/<div class='text silver'>([^<]*) (trophies?)<\/div>/i", $buffer, $psnsilver );
preg_match_all ( "/<div class='text gold'>([^<]*) (trophies?)<\/div>/i", $buffer, $psngold );
preg_match_all ( "/<div class='text platinum'>([^<]*) (trophies?)<\/div>/i", $buffer, $psnplatinum );

$psn = $psnid [1];
$level = $psnlevel [1];
$trophies = $psntrophies [1];
$bronze = $psnbronze [1];
$silver = $psnsilver [1];
$gold = $psngold [1];
$platinum = $psnplatinum [1];

for($i = 0; $i < count ( $psn ); $i ++) {

$psn [$i] = textlimit ( $psn [$i], 25 );

$trophies [$i] = preg_replace ( '/ Bronze|Silver|Gold|Platinum$/', '', $trophies [$i] );

}

$background = "themes/trophycard_1.png";
$imagename = "$username.png";
$imgpath = $_SERVER ['DOCUMENT_ROOT'] . "/trophycard/users/$username.png";
$im = imagecreatefrompng ( $background );
$black = imagecolorallocate ( $im, 0, 0, 0 );
$white = ImageColorAllocate ( $im, 255, 255, 255 );
$orange = ImageColorAllocate ( $im, 255, 180, 0 );
$red = ImageColorAllocate ( $im, 255, 0, 0 );
$font = 'fonts/visitor2.ttf';

imagettftext ( $im, 10, 0, 180, 35, $white, $font, $psn [0] );

header ( "Content-type: image/png" );
imagepng ( $im, $path );

?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.