Tonight I had to write a PHP page that would take the term parameter from a Google AdWords link and do something useful with it. The tricky part about this is that the term parameter is whatever random text the user plugged into the search engine. This was going to require lots of testing, because no doubt people will type all sorts of junk into that search box.
My URL had the shape:
http://somesite.com/somepage.php?term=<text users searched for>
I could have copied and pasted that URL into the browser, and then just edited it to have various combinations of text to experiment with. There are even keyboard shortcuts to make this relatively painless. But it still felt clumsy. Then it hit me - I could roll my own little bookmarklet to solve this problem.
First, I created a new bookmark for the site. I then edited the properties of the URL to say:
javascript:window.location='http://somesite.com/somepage.php?term='+escape(prompt("Term?"))
The magic, of course, is the prompt function which pops up a little JavaScript input box. The contents of the box are what's returned as the value of the prompt function. As a result, every time I hit this bookmark (which I had prominently on the link toolbar), I was asked to plug in a value for term.
I even took my setup a little further and added a debug mode to my somepage.php file. I set it up so that if it finds the parameter debug it just gives me a bunch of info as to what it would have done. I added the debug flag to the above recipe, and I had an instant interactive testing environment.
This whole bookmarklet approach seems like it could have all sorts of uses, way beyond simple testing like this. Definitely a hack to keep around.
posted by Shira Simon
ReplyDeleteShira hacks php? Cool. :)