Skip to content

Instantly share code, notes, and snippets.

@andrewmackrodt
Last active August 29, 2015 14:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrewmackrodt/6b0f4e9a6760def990d3 to your computer and use it in GitHub Desktop.
Save andrewmackrodt/6b0f4e9a6760def990d3 to your computer and use it in GitHub Desktop.
<?php
$sleep_time_sec = 30;
function get_page($url) {
$ch = curl_init($url);
curl_setopt_array(
$ch,
array(
CURLOPT_FOLLOWLOCATION => false,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 60,
CURLOPT_USERAGENT => 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:34.0) Gecko/20100101 Firefox/34.0'
));
$body = curl_exec($ch);
$info = curl_getinfo($ch);
if (false === $body || 200 !== $info['http_code']) {
trigger_error('Failed to retrieve the page', E_USER_WARNING);
}
return $body;
}
$list_of_sp = array();
while (true) {
$start = microtime(true);
$body = get_page('http://ps20.software.eu.playstation.com');
preg_match('/<script[^>]*>.*?config\.sp([^;]+);/s', $body, $matches);
if (isset($matches[1])) {
$sp = preg_replace('/["\' =]/', '', $matches[1]);
if (false === array_key_exists($sp, $list_of_sp)) {
$redirect_url = "http://ps20.software.eu.playstation.com/redirect.php?sp=$sp";
$claim_url = get_page($redirect_url);
$list_of_sp[$sp] = $claim_url;
echo "$sp\t=>\t$claim_url\n";
}
}
else {
trigger_error('Failed to locate the "sp" value', E_USER_WARNING);
}
$elapsed_sec = microtime(true) - $start;
if (($sleep_time_us = 1000000.0 * ($sleep_time_sec - $elapsed_sec)) > 0) {
usleep($sleep_time_us);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment