webtoolkit.info » PHP http://www.webtoolkit.info Code Snippets RepositoryThu, 20 Feb 2014 18:03:56 +0000en-UShourly1http://wordpress.org/?v=3.8.1PHP validate email http://www.webtoolkit.info/php-validate-email.html?utm_source=rss&utm_medium=rss&utm_campaign=php-validate-email http://www.webtoolkit.info/php-validate-email.html#commentsTue, 17 Feb 2009 19:59:41 +0000http://vectorfreebie.com/?p=190PHP validate email script is an easy way to validate an email address. Use this quick and simple PHP regular expression for email validation. This is also case-insensitive, so it will treat all characters as lower case. It is a really easy way to check the syntax and format of an email address. Function will […]

The post PHP validate email appeared first on webtoolkit.info.

]]>
PHP validate email script is an easy way to validate an email address. Use this quick and simple PHP regular expression for email validation. This is also case-insensitive, so it will treat all characters as lower case. It is a really easy way to check the syntax and format of an email address. Function will return TRUE if address is valid and FALSE if not.

Source code for webtoolkit.validate-email.php

/**
*
*  PHP validate email
*  http://www.webtoolkit.info/
*
**/
 
function isValidEmail($email){
	return eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email);
}


The post PHP validate email appeared first on webtoolkit.info.

]]>
http://www.webtoolkit.info/php-validate-email.html/feed0
PHP password protect http://www.webtoolkit.info/php-password-protect.html?utm_source=rss&utm_medium=rss&utm_campaign=php-password-protect http://www.webtoolkit.info/php-password-protect.html#commentsTue, 17 Feb 2009 19:57:43 +0000http://vectorfreebie.com/?p=188PHP password protect – is a script which you need to protect some page generated with PHP. Password protection for a single page. Visitors are required to enter a password and username to view the page content. Just include this function into your code, and call it at the top of your page with valid […]

The post PHP password protect appeared first on webtoolkit.info.

]]>
PHP password protect – is a script which you need to protect some page generated with PHP. Password protection for a single page. Visitors are required to enter a password and username to view the page content.

Just include this function into your code, and call it at the top of your page with valid USERNAME and PASSWORD.

Source code for webtoolkit.protect.php

/**
*
*  PHP password protect
*  http://www.webtoolkit.info/
*
**/
 
function passwordProtect($username, $password){
	if (
			(
				!isset($_SERVER['PHP_AUTH_USER']) ||
				(
					isset($_SERVER['PHP_AUTH_USER']) &&
					$_SERVER['PHP_AUTH_USER'] != $username
				)
			) &&
			(
				!isset($_SERVER['PHP_AUTH_PW']) ||
				(
					isset($_SERVER['PHP_AUTH_PW']) &&
					$_SERVER['PHP_AUTH_PW'] != $password
				)
			)
		)
	{
		header('WWW-Authenticate: Basic realm="Login"');
		header('HTTP/1.0 401 Unauthorized');
		echo 'Please login to continue.';
		exit;
	}
}


The post PHP password protect appeared first on webtoolkit.info.

]]>
http://www.webtoolkit.info/php-password-protect.html/feed0
PHP random password generator http://www.webtoolkit.info/php-random-password-generator.html?utm_source=rss&utm_medium=rss&utm_campaign=php-random-password-generator http://www.webtoolkit.info/php-random-password-generator.html#commentsTue, 17 Feb 2009 19:55:40 +0000http://vectorfreebie.com/?p=186PHP password generator is a complete, working random password generation function for PHP. It allows the developer to customize the password: set its length and strength. Just include this function anywhere in your code and then use it. Source code for password.php [crayon-53c29acd49756602925883/]

The post PHP random password generator appeared first on webtoolkit.info.

]]>
PHP password generator is a complete, working random password generation function for PHP. It allows the developer to customize the password: set its length and strength. Just include this function anywhere in your code and then use it.

Source code for password.php

<?php
 
function generatePassword($length=9, $strength=0) {
	$vowels = 'aeuy';
	$consonants = 'bdghjmnpqrstvz';
	if ($strength & 1) {
		$consonants .= 'BDGHJLMNPQRSTVWXZ';
	}
	if ($strength & 2) {
		$vowels .= "AEUY";
	}
	if ($strength & 4) {
		$consonants .= '23456789';
	}
	if ($strength & 8) {
		$consonants .= '@#$%';
	}
 
	$password = '';
	$alt = time() % 2;
	for ($i = 0; $i < $length; $i++) {
		if ($alt == 1) {
			$password .= $consonants[(rand() % strlen($consonants))];
			$alt = 0;
		} else {
			$password .= $vowels[(rand() % strlen($vowels))];
			$alt = 1;
		}
	}
	return $password;
}
 
?>


The post PHP random password generator appeared first on webtoolkit.info.

]]>
http://www.webtoolkit.info/php-random-password-generator.html/feed0