Ulyssesonline

the tech surfer

  • Home
  • About
  • Archives
You are here: Home / 2012 / Archives for April 2012

Archives for April 2012

April 10, 2012

What To Do With Your Old PC

There are many reasons why people upgrade their computers. It’s usually because the old hardware no longer works. Maybe it was simply too slow, or it doesn’t support any of the newer technologies. Whatever the case may be, people will usually end up with some old hardware that destined for donation or the scraps.

Run Linux

Before you part ways with your old hardware, you should really consider holding on to it a little while longer. I recommend that you install Linux on it. Why? Why not. Linux is fun operating system that has been around for almost 20 years. It’s powerful, educational, and most of all, it can breathe new life into that old crusty hardware.

Which Distro?

Linux comes in many flavors, which are called distributions, or distros for short. Which Linux distro is good for you? Well, it’s up to you. There are many, many to choose from. There are currently over 420 Linux distributions according to GNU/Linux Timeline. Most distros are active, with a few that are no longer supported.

Stick With The Popular

Debian, Ubuntu, Linux Mint, Redhat, Fedora, CentOS, and Slackware are just a few of the more popular distros. I recommend that you start with these distros. They are popular, well supported, and have thousand of users willing to help. Get familiar with the respected support forums in case you have an issue or two.

Try Before You Install

Most popular Linux distros will give you the option to try before installing it. I suggest that download the ISO images from directly from the distro websites. You will be asked to create a Live CD or DVD from the images, where you can boot from and run Linux. If you don’t like it, move on to the next one, until you find a distro you are comfortable with.

If you found one you really like, install it. Frequent the support forums for tips, solutions, suggestions, etc. Update your distros to keep up with the latest security patches and developments. Most of all, enjoy Linux.

Filed Under: Linux Tagged With: distro, hardware

April 9, 2012

Validate IP Addresses in PHP

Let’s say you were given a task to validate an IP address in a custom script. One approach is to use regular expressions and use pattern matching to see if user input is correct or not. In this example, we will use a regular expression below to validate IP addresses.

We assume user input is done via a form. First things first, we need to sanitize the input. Once sanitized, we can then test the input against the regular expression using a PHP function called the ereg().

// the regular expression for valid ip addresses
$reg_ex = '/^((?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?))*$/';
// sanitize input from form
$ip_address = addslashes(htmlspecialchars(strip_tags(trim($_POST['ip_address']))));
// test input against the regular expression
if (ereg($reg_ex, $ip_address)) { 
   // ip address is valid
} else {
   // ip address is not valid
}

// the regular expression for valid ip addresses $reg_ex = '/^((?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?))*$/'; // sanitize input from form $ip_address = addslashes(htmlspecialchars(strip_tags(trim($_POST['ip_address'])))); // test input against the regular expression if (ereg($reg_ex, $ip_address)) { // ip address is valid } else { // ip address is not valid }

The result is, we now have a facility to check the validity of IP addresses. We can now perform additional steps when the IP address is valid, or display errors if the IP address is invalid.

Filed Under: HTML, PHP Tagged With: IP address, regular expression

April 9, 2012

MySQL mysql_connect new_link

I want to share a database connection access problem I had last week, while working with a custom PHP script inside WordPress. I had created this WordPress Page Template containing some PHP code that needs access to the database. The problem was that the database connection for my custom script overwrote the WordPress database connection that was previously establish, causing certain parts of WordPress to not display properly.

It took me a while to figure out that it was the newer database connection of my custom PHP script that was causing the previously established WordPress database connection to disappear. Hence, certain parts of the WordPress page were not displayed. Little did I know, that the fix was quite simple. So, here’s a sample of my mysql_connect code. Prior to this line, I’ve already set the variables.

Mysql_connect

$db=mysql_connect($host,$username,$password);

$db=mysql_connect($host,$username,$password);

The Fix

Simply add a fourth parameter called new_link and set it to TRUE.

$db=mysql_connect($host,$username,$password,TRUE);

$db=mysql_connect($host,$username,$password,TRUE);

What this does is basically telling mysql_connect to establish a new connection, while keeping the older mysql_connect connection around, in case we need to access it at a later time. It’s amazing how one little switch in a command can make a huge difference to this seemingly simple code. Anyways, adding a fourth parameter and setting it to TRUE was the solution.

Filed Under: General, PHP, WordPress Tagged With: database, mysql, mysql_connect, new_link

  • « Previous Page
  • 1
  • 2
  • 3
  • Next Page »

Copyright © 2003 - 2018