Archive for May, 2011
QR Code and PHP – Quick project
by Aneal on May.13, 2011, under PHP, iPhone
Hello all,
I know I haven’t written anything useful here in a few months, but tonight as I was working on one of my big projects (PHP jukebox) I got a flash of inspiration and threw together a really quick and dirty little trick that many of you can duplicate in just a couple minutes.
Every day the line between what your TV does and your PC does is blurring. TV’s today are shipping with Netflix apps embedded, and your PC is no doubt packed with movies, music and other such media. Many of us however still have a pretty expansive DVD collection. I was thinking that I wanted a quick and easy way to watch any of my DVDs on my PC without having to take the disc outta the case, march it over to my PC, open the disc tray, launch etc. Even better, I wanted a way for ANYONE who comes over to my place to be able to do this. The answer? QR codes!
If you’ve been living under a rock for the last few years, you haven’t seen anything like this:
This is a QR Code. It’s basically a fancy bar-code that can holds lots more interesting data than just a UPC code. If you’ve got a smartphone, odds are you have some sort of QR reader already installed, or can grab one from the app store your phone is tied to. These codes are easy to generate too. There are several places on the web that will do it for you (even Google Charts will).
Basically, you can dump a phone number into the QR Code Generator, it’ll spit out a little QR code for you to use. When you scan that code w/ your iPhone, blamo it’ll dial the phone number. You can send a vCard to the QR generator, scan the output, blamo, you’ve added a contact to your phone’s address book.
The bit I used was to encode a URL into the QR Code.
Sooooo…
I grabbed one of the DVDs from my collection (Episode I, Star Wars of course), stuck it in my PC and ripped it to AVI. Then I wrote a small PHP file that lets me launch the file. It looks something like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
Let’s go over this:
First I check with an if statement if the Super Global $_GET is set. If it is, then I analyze the data that gets passed in (‘itemID’) with a switch statement. There’s only one case to check against in this demo, but you could theoretically write as many as you want. Heck, I’d even go a step further and create a small database to grab the files from there… But I digress…
Keep in mind that you’ll need to have this php file on your web server somewhere for any of this to work. I’ve got a Windows machine and use a WAMP stack for this. If you’ve read any of my other posts, you should already know what this is.
Next step, create a QR code! So I jumped out to Google Charts and generated a URL that points to that PHP file above on my WAMP server on my local network. In my case the URL was:
192.168.1.64/xampp/sandbox/phonelaunch?itemID=0
See the ?itemID=0 bit? That’s where the itemID comes into play with the GET super global in PHP. Anyhoo, PHP tutorials isn’t what this post is about.
Then I printed the code out, taped it to the back of my DVD case and done. Now all I have to do is make sure my phone is connected to the network, scan the code w/ my iPhone and my PC starts the movie, Jar Jar Binks and all.
One could theoretically rip every DVD, CD etc they owned, create a QR code for each and attach it to the case, tweak the PHP above and have your whole media library launchable from your phone. The cool part is when my girlfriend comes over, she can decide what we watch and launch the move from her phone too. No phone side code needed at all! Heck, if you knew my outside IP, you could launch a movie on my machine! Is this slick or what?!










