Make Your Phone ‘Kerching’ When You Make A Sale
Being the egotistical git I am, I wanted my phone to make a ‘kerching’ sound each time I made an affiliate sale. Nothing beats dozing off on a lazy Sunday evening and hearing your cash register ring out. Here’s how I made it happen…
First, you need to receive an email each time you make a sale. If your affiliate network will do this, then the first bit is already done. If not, copy the script below into a php file called something like ‘xml-to-email.php’ and upload it to your web server. Full instructions are in comments at the top of the file. You will most likely have to change the regex variable to work with your affiliate network’s own feed format.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 | <?php /* ######################################################### Email When You Make a Sale Developed by Hayden Kibble July 2009 Hayden@HaydenKibble.com www.HaydenKibble.com Install instructions: 1. Put your affiliate network login and your email details into the variables below 2. You will probably have to edit '$regex_saletime' to match the sale time/date for your paticular aff networks xml feed 2. Upload this file to your web server. 3. Create a file called 'sales.txt' in the same directory as this script and make sure it has read/write permissions 4. Visit the page and it should show a blank page. An email will probably be sent as it picks up all your recent sales 5. Set a cron job up on your web server to run this script every 10 mins or so 6. If you have problems with any of the above, Google is your friend! ######################################################### */ $base_url = "https://www.affilliate-network.com/myfeed.xml"; $feed_user = "USERNAME-HERE"; $feed_pass = "PASSWORD-HERE"; $regex_saletime = "/<date>(.*)<\/date>/U"; $email_from = "from@address.com"; $email_to = "to@address.com"; $email_subject = "You Made a Sale!"; // ##### Do Not Edit Below This Line! ##### $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $base_url); // Set your login and password for authentication curl_setopt($ch, CURLOPT_USERPWD, $feed_user . ':' . $feed_pass); curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // get the data and close the session $data = curl_exec($ch) or die("Error Getting Feed."); curl_close($ch); $dates = array(); preg_match_all($regex_saletime,$data,$dates); // Read previous sales times from database $fileData = array(); $myFile = "sales.txt"; $fh = fopen($myFile, 'r'); $fileData = fread($fh, filesize($myFile)); fclose($fh); // Split the file into lines $fileLines = explode("\n",$fileData); $newsale = false; $fh = fopen($myFile, 'a') or die("can't open file"); // See if this sale has already been logged. If not, log it and set 'new sale' variable foreach($dates[1] as $date){ if (!in_array($date,$fileLines)){ $newsale = true; $sale_time = $date; fwrite($fh, $date . "\n"); } } fclose($fh); if ($newsale){ mail($email_to,$email_subject,"You have made a sale.\nSale Time: ".$sale_time,"From: " . $email_from); } ?> |
To test, empty the sales.txt file you created and run (access) the script. It will see your recent sales have not been logged and fire off the email. Make sure the email does not go to your junk folder.
If you want your computer to play a ‘kerching’ upon making a sale, you can simply set up a rule in Microsoft Outlook to play the sound upon receiving an email with ‘Payment Received’ in the subject. You get the idea.
For those of you who want the full-on portable cash register, continue on to create a gmail account with a difficult to guess name just for these emails. If you share this address anywhere it will get spammed. We do not want this as you will start hearing an awful lot of incorrect kerching’s!
You now need to set your phone up to use your gmail account. Make it check for new emails every 10 mins or so (depending on how often you set your cron job to run the script) and set this kerching wav as your notification sound.
You are now set! When the php script runs intermittently on the cron job, it parses the feed for new sales. When it finds a new sale it sends an email to your phone, which plays a ‘kerching’ sound on receipt!