How to Download the AppStore Top Free iPhone Apps
To download a copy of the current AppStore Top Free iPhone Apps, you can write a script that will do it for you. The script is written in PHP and it will download the complete list of apps as shown through iTunes.
First thing you need to do is set your user-agent string. Apple will detect what browser you are using and if it isn't iTunes, it will try and launch iTunes from your browser.
// Set user agent to iTunes (required)
ini_set('user_agent', 'iTunes/9.0.2 (Macintosh; Intel Mac OS X 10.5.8) AppleWebKit/531.21.8');
Next you will need to specify where you will save the downloaded file.
// Local path to local directory $localPathToSave = './';
Set the path from the App Store to download the file.
// Remote path to iTunes AppStore and path structure $remotePathToAppStore = 'http://ax.itunes.apple.com/WebObjects/MZStore.woa/wa/viewTop?id=25204&popId=27';
This is an optional step so that label the downloaded file the time and date that it was retrieved.
// Get current date and time stamp
$curDateTime = date("Y.m.d.Hi");
Construct the variables that we are going to use for the remote and local file locations.
// Declare paths to files $remoteFile = $remotePathToAppStore; $localFile = $localPathToSave . 'AppStoreTopFreeiPhoneGames.'. $curDateTime . '.html';
Copy the file for the remote location (App Store) to the local location (your server). This is done in a if statement so we can catch any errors that occur in the process.
// Copy remote file to local
if(!@copy($remoteFile, $localFile)) {
$errors = error_get_last();
echo "COPY ERROR: " . $errors['type'] . ' ' . $remoteFile . ' ' . $localFile;
echo "<br />n" . $errors['message'];
}
Optional step to free up memory from some of the memory from the used variables. This would be useful if this was part of a larger script that was downloading multiple files.
// Free up memory by releasing variables unset($remoteFile); unset($localFile); unset($errors);
Download the full code in the Download Code section.