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: Set Up Your Own Snort Intrusion Detection System with a Database Backend

Okay, truth told, I’m completely bored, so I’m going to write a quick tutorial on how to install and set up the Snort IDS on a Debian Sarge System (although it should work on other distros as well).

Download and Install Snort
apt-get install snort-mysql

Enter values in the following screen, but forget about the part about the database
cd /usr/share/doc/snort-mysql
mysqladmin -u -p create
zcat create_mysql.gz | mysql -u -p

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

Howto: Get a Movie from a DVD to your Sony Clie (and probably other PDA’s as well)

I’ll try to make this as simple as possible.

I’m going to assume that you’re using Linux (and that you are not a complete noob at it) for this tutorial. I will assume that you’re using a Sony Clie.

Here’s an overview of what we’re going to do:

  1. Rip dvd using DVD:Rip
  2. Convert ripped movie into a clie compatible format
  3. Download and install TCPMP (free media player)
  4. (optional) Install Memory Stick Pro fix
  5. Copy Movie to the Memory Stick

Step 1: Download and Install Files
apt-get install dvdrip
apt-get install pilot-link
Download TCMP (for palm)
Download all attachments

Step 2: Rip DVD
Encode with the xvid4 codec
Set file size to One CD at 700Mb
The only reason that I have this step is because I like to watch the video in high quality on my desktop

Step 3: Convert ripped DVD to Palm Readable Format
Put the following into a script called vid2palm and make it executable

#Change 480:320 to the size of your PDA screen
#480:320 works for the Sony Clie

nice mencoder $1 -vf scale=480:320 -ovc xvid -xvidencopts bitrate=300 -oac mp3lame -lameopts cbr:br=64 -o $2
So, if dvdrip created the file MyMovie.avi you’d run the command vid2palm MyMovie.avi MyMovie_Palm_Format.avi

Step 4: Install files on your Clie
This can be a little tricky for someone doing it for the first time, but after a couple of times it works great.

The syntax for installing a palm file is:
pilot-xfer /dev/pilot -i [File to be installed]

However, If you just run this command it won’t work. You first need to hit the hotsync button and then quickly run the previous command.

If you do this and the console says to press the hotsync button, just hit cancel on your clie, and terminate the command, and try again. It’s been a bit of hit-and-miss for me.

Files to install on the PDA from the TCPMP Archive:

  • pilot-xfer /dev/pilot -i tcpmp_ffmpeg_plugin.prc
  • pilot-xfer /dev/pilot -i tcpmp_mp3_plugin.prc
  • pilot-xfer /dev/pilot -i tcpmp_mpeg4_plugin.prc
  • pilot-xfer /dev/pilot -i tcpmp.prc
  • As well as the attached tcpmp_aac_plugin.prc
  • If your memory card is a memory stick pro it will not work by default with the clie, so you have to install a fix for it (it’s the MSPRONX_ENUS.PRC one):
    pilot-xfer /dev/pilot -i MSPRONX_ENUS.PRC

    Sound doesn’t work by default on mine either, I had to install the following patch (again, an attachment: MCA2_05_TEST.prc):
    pilot-xfer /dev/pilot -i MCA2_05_TEST.prc

    You need to set up this plugin by going to prefrences and then in the drop down menu select MCA2, and check the button “auto install after reset”. It will restart, then go back to the same area and select “DEFAULT is ON (normal)”.

    Step 5: Moving the finished product to your Memory Stick (pro)
    First, goto MS Import. If you have a newer distro / kde it will mount the flash drive as a local directory. If it doesnt, use the “mount” command to mount it. I assume that you know how to do this (if you don’t try “man mount”).

    Now it’s a bit of a waiting game. Once it looks like it’s done copying unmount the device in linux first, wait a minute, and then disconnect in MS Import.

    Step 6: Play the Movie
    Goto TCPMP, open, and play your movie!

    This is how I did it, after a week or so of trying.

    If you have any questions leave a comment or email me (howe -dot- jon -at- gmail -dot- com.

    Jon Howe