Featured Posts

FuelPHP Command Line Oil with Windows BAT File And... I have been using the Codeigniter PHP MVC framework for awhile now and have started to realize I need some extra features that are not built in by default.  A few weeks ago...

Readmore

PHP Class To Build HTML Forms I have recently pushed a new repository to Github to showcase a PHP class I built.  This class helps make building HTML forms easier.  I originally built this class to help...

Readmore

Codeigniter Library to Read CSV File I recently posted some code to Github that I created for use in Codeigniter. I built a library that can be used to read CSV files, extract the data you need, and return a...

Readmore

Using PHP Curl To Check Apple Site To See If My Extension... A few weeks ago (probably closer to months now) I built a Safari extension.  I also submitted it to Apple to see if it can be listed on their Safari extensions page.  I...

Readmore

Safari Extensions - Puni.co URL Redirection For anyone interested in URL redirection services and Safari Extensions, here is a service offered by TheBizzTech LLC.  We have made a Safari Extension that uses the free puni.co...

Readmore

TheBizzTech Rss

Using PHP Curl To Check Apple Site To See If My Extension Is Listed

Posted on : 26-04-2011 | By : TheBizzTech | In : Curl, Mac OS, PHP, Puni URL Redirection, Safari, Safari Extensions

Tags: , , , ,

3

A few weeks ago (probably closer to months now) I built a Safari extension.  I also submitted it to Apple to see if it can be listed on their Safari extensions page.  I have not heard anything back for a while and have gotten sick of constantly going to their website and searching through the hundreds of extensions to see if mine has been listed.

I have decided to automate my search using PHP and Curl.  This way whenever I remember to check to see if my extension is listed I can just run this page in my browser and it will check the site for me and tell me if I am listed yet.

Here is the code and then I will kind of go through it.

<?php
// create a new cURL resource
$ch = curl_init();
// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, "http://extensions.apple.com");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
// grab URL
$result = curl_exec($ch);
$findme = 'puni';
$pos = strpos($result, $findme);

if ($pos === false)
{
echo "The string '$findme' was not found on the safari extensions site.";
}
else
{
echo "The string '$findme' was found in the safari extensions site and exists at position $pos";
}
// close cURL resource, and free up system resources
curl_close($ch);?>

First thing you do is you have to initialize curl into any variable you would like, I use $ch because it seems to be the most common. Next you have to set the headers. There are numerous headers you can set, but you must make sure to set “CURLOPT_RETURNTRANSFER, TRUE”. Basically TRUE means you will return the webpage as a string, instead of outputing the result directly to the browser. You can read more about the option headers here.

After you set the headers you run curl_exec($ch) to actually process the data and return the value as a string into the $result variable. One you do this you set the string you are looking to find and use strpos to find your string nested inside the data from the site.

Now since I am searching for the word puni, since my extension is called puni.co, I am fairly sure no other extensions are going to have this name. If they do I would get a false positive. In the case that I ever get a success and puni is found but it was not my extension, then I will do some simple modification to search for something more explicit.

If strpos does not find the nested string it will return false. So all you need to do is check for false and if it is not false then you have a success, and print out your success message.

If really was serious and wanted to know the exact day my extension was listed I could setup this script to email me and setup a cron job to run every day. Since I am not too worried about when I get listed I am fine just running the script when I think about it.

This way I only have to visit their site once I have a fairly good change that my amazing extension (I am a bit partial) is listed.

Comments (3)

I learned a lot from this post, much appreciated! :)

This article is a home run, pure and spimle!

This is way more helpful than aynthnig else I’ve looked at.

Write a comment