0

The below block of code generates stuff like the below array but here's where it gets somewhat interesting. I took the legend and turned them all in to variables because of what I would like to have done which I will now describe below.

Of the four arrays that this code produces I would like to take the [http_code] from each one and have it display the legends variable data. This way each time it's run I don't need to check the legend to see what the HTTP code means. So... what needs to be done to achieve this ?

Edit: To even take it one step further since some people say I don't always full describe myself. Using the below array I would expect to see [http_code] => (200) OK instead of [http_code] => 200 when this modifications done since (200) OK is what the variable legend says to display for 200.

U2Array
(
=> http://www.naughtydog.com/stats/index/MoreBloodWine
[content_type] => text/html; charset=UTF-8
[http_code] => 200
[header_size] => 780
[request_size] => 476
[filetime] => -1
[ssl_verify_result] => 0
[redirect_count] => 0
[total_time] => 2.874797
[namelookup_time] => 0.277131
[connect_time] => 0.331046
[pretransfer_time] => 0.331058
[size_upload] => 0
[size_download] => 41772
[speed_download] => 14530
[speed_upload] => 0
[download_content_length] => -1
[upload_content_length] => 0
[starttransfer_time] => 2.675769
[redirect_time] => 0
)
U2 level found. No error. (Card gen checks on this or will inprint U2 error.)


<?php

// Begin HTTP Code Legend
// [Informational 1xx]
$_100 = "(100) Continue";
$_101 = "(101) Switching Protocols";

// [Successful 2xx]
$_200 = "(200) OK";
$_201 = "(201) Created";
$_202 = "(202) Accepted";
$_203 = "(203) Non-Authoritative Information";
$_204 = "(204) No Content";
$_205 = "(205) Reset Content";
$_206 = "(206) Partial Content";

// [Redirection 3xx]
$_300 = "(300) Multiple Choices";
$_301 = "(301) Moved Permanently";
$_302 = "(302) Found";
$_303 = "(303) See Other";
$_304 = "(304) Not Modified";
$_305 = "(305) Use Proxy";
$_306 = "(306) (Unused)";
$_307 = "(307) Temporary Redirect";

// [Client Error 4xx]
$_400 = "(400) Bad Request";
$_401 = "(401) Unauthorized";
$_402 = "(402) Payment Required";
$_403 = "(403) Forbidden";
$_404 = "(404) Not Found";
$_405 = "(405) Method Not Allowed";
$_406 = "(406) Not Acceptable";
$_407 = "(407) Proxy Authentication Required";
$_408 = "(408) Request Timeout";
$_409 = "(409) Conflict";
$_410 = "(410) Gone";
$_411 = "(411) Length Required";
$_412 = "(412) Precondition Failed";
$_413 = "(413) Request Entity Too Large";
$_414 = "(414) Request-URI Too Long";
$_415 = "(415) Unsupported Media Type";
$_416 = "(416) Requested Range Not Satisfiable";
$_417 = "(417) Expectation Failed";

// [Server Error 5xx]
$_500 = "(500) Internal Server Error";
$_501 = "(501) Not Implemented";
$_502 = "(502) Bad Gateway";
$_503 = "(503) Service Unavailable";
$_504 = "(504) Gateway Timeout";
$_505 = "(505) HTTP Version Not Supported";
// End HTTP Code Legend

error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE);

$psn = 'MoreBloodWine';

echo '<html><head></head><body>';

$header[0] = "Accept: text/xml,application/xml,application/xhtml+xml,";
$header[0] .= "text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5";
$header[] = "Cache-Control: max-age=0";
$header[] = "Connection: keep-alive";
$header[] = "Keep-Alive: 300";
$header[] = "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7";
$header[] = "Accept-Language: en-us,en;q=0.5";
$header[] = "Pragma: ";

global $u2status, $status, $status2, $status2_u2, $APRT;

// Begin DATA
// U2
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://www.naughtydog.com/stats/index/'.$psn.'');
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (X11; U; Linux i686; en-GB; rv:1.9.0.3) Gecko/2008101315 Ubuntu/8.10 (intrepid) Firefox/3.0.3');
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_ENCODING, 'gzip,deflate');
curl_setopt($ch, CURLOPT_AUTOREFERER, true);
//curl_setopt($ch,CURLOPT_FOLLOWLOCATION,1);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);

$u2data = curl_exec ($ch);
$u2status = curl_getinfo($ch);
curl_close($ch);

// PSN 1 (Cookie key)
$ch2 = curl_init();
curl_setopt($ch2, CURLOPT_URL, 'http://us.playstation.com/publictrophy/index.htm?onlinename='.$psn.'');
curl_setopt($ch2, CURLOPT_USERAGENT, 'Mozilla/5.0 (X11; U; Linux i686; en-GB; rv:1.9.0.3) Gecko/2008101315 Ubuntu/8.10 (intrepid) Firefox/3.0.3');
curl_setopt($ch2, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch2, CURLOPT_ENCODING, 'gzip,deflate');
curl_setopt($ch2, CURLOPT_AUTOREFERER, true);
//curl_setopt($ch,CURLOPT_FOLLOWLOCATION,1);
curl_setopt ($ch2, CURLOPT_HEADER, 1);
curl_setopt($ch2, CURLOPT_NOBODY, 1);
curl_setopt ($ch2, CURLOPT_RETURNTRANSFER, 1);

$APRTdata = curl_exec ($ch2);
$status = curl_getinfo($ch2);
curl_close ($ch2);

// PSN 2 (PSN data)
$ch3 = curl_init();
curl_setopt($ch3, CURLOPT_URL, 'http://us.playstation.com/playstation/psn/profiles/'.$psn.'/');
curl_setopt($ch3, CURLOPT_USERAGENT, 'Mozilla/5.0 (X11; U; Linux i686; en-GB; rv:1.9.0.3) Gecko/2008101315 Ubuntu/8.10 (intrepid) Firefox/3.0.3');
curl_setopt($ch3, CURLOPT_COOKIE, 'ARPT='.$APRT[1].'');
curl_setopt($ch3, CURLOPT_REFERER, 'http://us.playstation.com/publictrophy/index.htm?onlinename='.$psn.'');
curl_setopt($ch3, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch3, CURLOPT_ENCODING, 'gzip,deflate');
curl_setopt($ch3, CURLOPT_AUTOREFERER, true);
//curl_setopt($ch3,CURLOPT_FOLLOWLOCATION,1);
curl_setopt ($ch3, CURLOPT_RETURNTRANSFER, 1);

$profile = curl_exec ($ch3);
$status2 = curl_getinfo($ch3);
curl_close ($ch3);

// PSN 3 (U2 Plat)
$ch4 = curl_init();
curl_setopt($ch4, CURLOPT_URL, 'http://us.playstation.com/playstation/psn/profiles/'.$psn.'/trophies/581961-Uncharted-2-Among-Thieves/');
curl_setopt($ch4, CURLOPT_USERAGENT, 'Mozilla/5.0 (X11; U; Linux i686; en-GB; rv:1.9.0.3) Gecko/2008101315 Ubuntu/8.10 (intrepid) Firefox/3.0.3');
curl_setopt($ch4, CURLOPT_COOKIE, 'ARPT='.$APRT[1].'');
curl_setopt($ch4, CURLOPT_REFERER, 'http://us.playstation.com/publictrophy/index.htm?onlinename='.$psn.'/trophies/581961-Uncharted-2-Among-Thieves/');
curl_setopt($ch4, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch4, CURLOPT_ENCODING, 'gzip,deflate');
curl_setopt($ch4, CURLOPT_AUTOREFERER, true);
//curl_setopt($ch3,CURLOPT_FOLLOWLOCATION,1);
curl_setopt ($ch4, CURLOPT_RETURNTRANSFER, 1);

$profile_u2 = curl_exec ($ch4);
$status2_u2 = curl_getinfo($ch4);
curl_close ($ch4);
// End Data

echo '
<pre><b>U2</b>: '.$u2status['http_code'].'
<b>PSN 1 (Cookie key)</b>: '.$status['http_code'].'
<b>PSN 2 (PSN data)</b>: '.$status2['http_code'].'
<b>PSN 3 (U2 Plat)</b>: '.$status2_u2['http_code'].'</pre>
';

echo '---------------------<br /><br />';
 
if (preg_match('/<h1>Error Retrieving Statistics<\/h1>(.+?)<p>/s', $u2data, $error))
{

   if(!empty($error[1]))
      $errormsg = trim($error[1]);
   else
      $errormsg = '';

   echo 'Error Retrieving Statistics: '.$errormsg;
}else{

   echo 'No error reported on U2 site.';

}

echo '<pre><b>U2</b><br />';
print_r($u2status);
preg_match('/<span class="StatLabel">Level:<\/span> (.+?)<br \/>/s', $u2data, $level);
if (empty($level[1]))
   echo 'U2 level retrieval failed. (Card gen checks on this or will inprint U2 error.)';
else
   echo 'U2 level found. No error. (Card gen checks on this or will inprint U2 error.)';

echo '</pre>';

echo '---------------------';
 
echo '<pre><b>PSN 1 (Cookie key)</b><br />';
print_r($status);

preg_match('#ARPT=(.+?);#', $APRTdata, $APRT);

if (!empty($APRT[1]))
   echo 'Cookie key: ' . $APRT[1] . ' (needed for the PSN data)';
else
   echo 'Cookie key retrieval failed.';
echo '</pre>';

echo '---------------------';

preg_match('#/avatar_s/(.+?)_s#', $profile, $ava);

if (empty($ava[1]))
   preg_match('#/avatar_s/(.+?)s#', $profile, $ava);
    
echo '<pre><b>PSN 2 (PSN data)</b><br />';
print_r($status2);
if (empty($ava[1]))
   echo 'PSN avatar retrieval failed. (Card gen checks on this or will inprint PSN error.)';
else
echo 'PSN avatar found. No error. (Card gen checks on this or will inprint PSN error.)';

echo '</pre>';

echo '---------------------';

echo '<pre><b>PSN 3 (U2 Plat)</b><br />';
print_r($status2_u2);

preg_match('/text platinum">(.+?) Platinum<\/d/s', $profile_u2, $u2_plat);

$U2STATS['u2_platinum'] = trim($u2_plat[1]);
if (!isset($U2STATS['u2_platinum']))
   echo 'PSN 3 U2 Plat retrieval failed';
else
echo 'PSN 3 U2 Plat found. No error.';

echo '</pre></body></html>';

?>
2
Contributors
1
Reply
3
Views
6 Years
Discussion Span
Last Post by jimforsyth
0

Hi MoreBloodWine,

You could loop through the array and replace the data with that of the legend:

foreach( $U2Array as $key => $item ) {
	if ( $key == "http_code" ) $U2Array[$key] = ${'$_'.$U2Array[$key]}; 
}

If you haven't sorted this out already, I hope you find this useful.

Kind regards

Jim :)

Edited by jimforsyth: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.