shadysaiyan Posted August 25, 2009 Share Posted August 25, 2009 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 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 ); ?> Quote Link to comment Share on other sites More sharing options...
Alex Posted August 25, 2009 Share Posted August 25, 2009 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; } Quote Link to comment Share on other sites More sharing options...
shadysaiyan Posted August 25, 2009 Author Share Posted August 25, 2009 how would i implement that into my current code? i'm no expert. Quote Link to comment Share on other sites More sharing options...
oni-kun Posted August 25, 2009 Share Posted August 25, 2009 Things may seem simpler than they seem.. $buffer = getPage($url); If you look in his code, it says 'return $html', so the function would naturally be assumed to return the pages contents, such as you wanted. Quote Link to comment Share on other sites More sharing options...
shadysaiyan Posted August 25, 2009 Author Share Posted August 25, 2009 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 ); ?> Quote Link to comment Share on other sites More sharing options...
shadysaiyan Posted August 26, 2009 Author Share Posted August 26, 2009 Nevermind, figured it out myself. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.