1
What is AJAX?
2
Google likes standards compliance
3
Make Your Phone ‘Kerching’ When You Make A Sale

What is AJAX?

AjaxWhat is AJAX?
If you find yourself asking this question then you’re either new to PHP/Javascript or you have been hiding under a rock for the past three years.
Since around 2006, the term/buzzword ‘AJAX’ has been thrown around like a frisbee in a playground. So what exactly is AJAX?

If you’ve had an auto-suggest bubble pop up as you’re searching, or if you’ve seen form sub-sections magically appear as you choose options, then you have already used AJAX. Slow, static web pages have given way to speedy, animated interfaces with more nifty features.

Some examples of what you can achieve with AJAX include:

  • Auto-suggest popups
  • Form elements appearing/hiding as you complete the form
  • Slider controls
  • Draggable/droppable content

The term AJAX stands for ‘Asynchronous Javascript And XML’. Technically, AJAX is when javascript sends requests back to the server, receives a response in XML and acts upon it. These days though, AJAX is used more of a blanket term of for anything interactive which uses javascript.

If you have been developing PHP and looking to take your applications to the next level of interactivity, then check out some of the nifty AJAX Javascript frameworks out there that do all the hard work for you:

Google likes standards compliance

standards complianceOne thing I love about the SEO world is that it’s not an exact science. Just about every man and his dog have their own idea about what Google likes and hates.

I think we’re all agreed on the fact that relevant, contextual links from related so-called ‘authority’ sites are good stuff. Generous use of your keywords through your title tag, header tags and page content are also top of the list in our SEO agendas.

Well, what then? What else can we do to be Google’s best friend? Some recent theories have been thrown about such as:

  • Get contact us, terms and about us pages
  • Add a quick blog to your site and other ‘bulking’ things
  • Put your keywords into image ALT tags

But I’ve never heard anyone state the importance of making your sites (X)HTML compliant. I am confident that the big ‘G’ sees this as a big deal, but Nobody seems to have noticed. Just look how clear Google makes this point in their webmaster guidelines:

Check for broken links and correct HTML

Easy to overlook, but even easier to adhere to. Simply let the W3C’s free online validator take a look at your page and tell you how to fix it. Job done!

And in case you’re wondering, of course I have 🙂

Make Your Phone ‘Kerching’ When You Make A Sale

cash-registerBeing 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!

Copyright © 2018. Created by Hayden Kibble.