AJAX Based MySql Live Search

This is a little something that I made up this afternoon at school.

It’s an implementation of a search app with out a celing. In other words , there’s no submit button. With each keystoke that you type, the query get’s more accurate.

If you just want to check it out (with source, and an example) then Click Here
The code is commented pretty well.

If you want a little explanation read on.

I used a library called Xajax for this project (and the last one as well). It’s an extremely useful and easy to use library because of the fact that it doesn’t require the coder to know any javascript. This is a goood thing, because I HATe javascript.

The Xajax library allows you to take a PHP function and essentially use it as a javascript function asynchronously.

What this script does is check to see if the user presses a key. Each time that they do the PHP function autoSearch() runs. autoSearch() has one paramater, the current value of the input box. Read the code comments for more info on this.

If the entered query is 2 or more charachters, then a mysql query is executed. If there are result(s), then they are diplayed.

Practical Application:
Personally, I hope to use this in the content mananagement system that I’ll be starting soon. I’m planning on having it parse through blog entries, and display the title and the publishing date of the post.

When you click on the link above you’ll see the example page. At the bottom of it are links to the PHP source, as well as the MySql Source.

If you have any questions email me at “howe -dot- jon – at – gmail – dot – com”, and I’ll get back as soon as I can.

Jon Howe

Howto: AJAX Regular Expression Email Verifier

It’s important to do form validation for obvious reasons. This is an implementation of an email checker that uses php regular expressions, and a little bet if pizzaz with asynchronous javascript and xml, or AJAX.

Here’s the example.

A quick rundown of how this works is:

  1. You type in a string
  2. You hit submit
  3. The data is transfered asynchronously (without refreshing the page) to the server
  4. The server checks to see if the email is valid or invalid
  5. If it’s valid it tells you so, as well as if it’s not
  6. The guts of the script are here:
    if (eregi("^[a-zA-Z0-9_-.+]+@[a-zA-Z0-9-]+.[a-zA-Z0-9-_.]+$",$email)) {
    //return confirmation that it worked
    else {
    //return that it didn't work

    Basically, it checks to see if there’s either a lowercase or uppercase a-z or 0-9 or an underscore, or a dash, or a period before the @ sign ([a-zA-Z0-9_-.+]+@). Then after the @ sign it checks for the same thing except for the period and the underscore up until another dot. After that dot it checks once again for the same charachters as the first set.

    Hopefully this helps someone. If you have any questions feel free to email me at “howe -dot- jon -at- gmail -dot- com” and I’ll help you however I can.

    Jon Howe

HOWTO: Create a Logging Redirection Page using PHP and MYSql

Since I’ve already been on the topic of doing small beginner PHP tutorials, here’s another one. This one is pretty self explanitory.

You can see it here.

Basically what this does is let you enter a domain or page or whatever and it redirects you to the page. On top of just redirecting you, it logs all of the redirections along with the request date, and requester ip address.

If you have a need for this, you’ll most likely know how to implement it. If not, feel free, as always, to email me (howe -dot- jon -at- gmail -dot- com), and I’d be happy to help you out to the best of my abilities.

Jon Howe

Howto: PHP Secure Download Script

I’ve been wanting to make a script in PHP that handles downloads for a while. Last night I was bored, so I made one.

This is a very basic example, but if you have any use for this, I’m sure that you can figure out how to use it. If not, I’ll probably work more with it in the future anyways.

This system works with two PHP files.

If you just want to see the script work, go Here.

From there you can download a sample file and see the source of the scripts.

Now, for how it works…

All that the first script (dl.php) does is display a link to the main download script (which handles the actual download) and sets a session variable for 60 seconds in the future.

Once you click on the link, the main download script (dl2.php) sets another session variable containing the time that the link was clicked.

It checks to see if the time that dl.php was generated no more than 60 seconds later than the link was clicked. If it was later than that the download fails.

Feel free to email me (howe -dot- jon -at- gmail -dot- com) if you have any questions, or requests or whatever, and I’ll do my best to get back to you that day.

Jon Howe

Convert RPM to Deb + News

I found a few cool things this morning.

The first being a way to install a rpm file in Debian. You do this using the alien command (apt-get install alien).

To convert a package from an rpm to a deb run the following command:
alias --to-deb

To just install a rpm use the following command:
alias -i

It's that easy.

Also, I was looking at some stories on the front page of Digg, and found a Great New Library for use with Google Maps. It has the features of the one that I was messing around with earlier (I forgot the name of it). It even includes the features that I had to add inot the other library.

Who knows, you might be getting a little tutorial on how to use this library soon.

Jon Howe

How to Create a PDF Document from PHP

In this project that I’ve been messing with, I’ve come across the need to convert dynamic PHP output to a PDF.

Suprisingly, this is a pretty easy process thanks to DomPDF.

Boy is this ever hard.

Check it out below!
(Reminder – you’re going to need to have Adobe Acrobat Reader for this to work, seeing as how thi s is a PDf generator. You probably already have it, but in case you don’t, here it is.

<br />

Let me know what you think.


News / Ideas

I decided after reading all of chapter 2 and part of chapter 3 in my AJAX book that I need to learn Javascript better before I go further with AJAX, because It’s based on Javascript. Fortunately I have a really good Javascript book that I’m about 1/8’th of the way done with.

As for news…

I’m working on a ton of features daily on this site that I’m making (which I could still use some testers (Email me) for. One feature that’s been annoying me, as I’ve been trying to implement it is the functionality to have the site remember someone after they log out.

Last night before I went to bed I had had it with not being able to figure it out, so I brainstormed, and wrote out a two page instruction sheet for myself on how to do it.

If you already know PHP, and think that this is easy, you’re right, usually. The problem was, that I didn’t plan to have this functionality when I made the site, and it was hard to find a way to to fit it in once it was already made.

So, I’m going to go to school in 15 minutes, get home around 12:45, then start adding this functionality to this site. Afterwards I’m going to make another entry with examples on how to do it.

Jon Howe

Web Design

So over the past few months I’ve been working on a website for someone. The website’s going to be used sort of as a utility website for employees at car dealerships around Michigan.

I haven’t mentioned a lot about it, because it’s not quite ready yet, and it’s a bit secretive at this point.

However, it is coming along pretty well at this point. The user interface is done (for the most part), and a new site design is being made by someone that is very good at making site designs. All that has to happen is a calculation has to be transferred from one language into the language that the site is in.

Sometime in the near future I could use some help from (preferably) people that I know to beta test the user interface.

If you’re interested in trying to break my site, feel free to contact me via email at this email address

Jon Howe