Publications

How to Sending E-mail With PHP?

Fadıl

Every web site has email.  Rather it being a feedback form of some sort or a mailto: tag, why make it hard for the visitor to contact you?  When you can take 3 lines of code and create a feedback form the directly sends it to your email from the web browser with the visitor’s input.

Creating a PHP Email form could be the best thing that has ever happened to your site.  So how do you do it? Easy.
You can have any one of your pages send an email when the visitor either visits the page or if the visitor has submitted some sort of input.  When you add the code it needs to be at the top of the page you would like to send from.

Ip Check Using PHP

Fadıl

If you have ever had the need to validate an IP address then this small script is for you.

function validate_ip($ip) {
if (is_string($ip) && ereg('^([0-9]{1,3}).([0-9]{1,3}).' .
'([0-9]{1,3}).([0-9]{1,3})$',
$ip, $part)) {
if ($part[1] <= 255 && $part[2] <= 225 && $parg[3] <= 255 && $part[4] <= 255)
return TRUE; # Valid IP
}
return FALSE; # Invalid IP
}

Ok, that’s all fine and dandy but what does it mean?

The fist if the statement is breaking the IP up into 3 sections and removing the ‘.’ from the user input. It then stores the results in the $part var then the second If statement checks to see if all of the parts are valid. If everything is fine and dandy it will return TRUE and if something has gone wrong it will return FALSE.
Hope this helps anyone.

How to create a random password in PHP

Fadıl

I am trying to generate a random password in PHP.

If you ever have the need to create a random password or username you can use something like this.

function randomPassword($length) { 
  $possible = '0123456789!@#$%^&*()_+' . 
              'abcdefghijklmnopqrstuvwxyz' . 
              'ABCDEFGHIJKLMNOPQRSTUVWXYZ' . 
  $str = ""; 
  while (strlen($str) < $length) { 
     $str .= substr($possible, (rand() % strlen($possible)), 1); 
  } 
  return($str); 
}

How to Database-Driven User Authentication?

Fadıl

Ever have something that you wanted to put on the internet for only a group of
people to see? Well, then this script is for you. All you need is; PHP and MySQL.
Create a MySQL database to store the usernames and passwords.

CREATE TABLE auth_users ( 
  f_name varchar(50) DEFAULT '' NOT NULL, 
  l_name varchar(50) DEFAULT '' NOT NULL, 
  username varchar(50) DEFAULT '' NOT NULL, 
  password varchar(100) DEFAULT '' NOT NULL 
  );

Now that you have a table named auth_users, you can now create an interface to add First names, Last Names, usernames, and passwords.

How to install ssh on Linux?

Fadıl

Building and Installing SSH

For most Unix systems, the installation of SSH is pretty straightforward. Simply download the GNU-zipped tar file from one of the FTP mirror sites listed at http://www.ssh.fi/sshprotocols. (Note: Typically there’s a new version of SSH released every few months.) In order to compile SSH, you need an ANSI C compiler such as gcc. The simplest way to build this software is to do the following:

# ./configure

# make

# make install

The configure script should recognize your system type, discover important information about your build environment, and–if everything checks out–create a corresponding Makefile. The make program uses this Makefile to build the software. The make install directive installs the SSH components and man pages in the right places and generates the initial 1024-bit host key pair (if it doesn’t already exist).