Skip to content
Snippets Groups Projects
validation.lib.php 1.02 KiB
Newer Older
  • Learn to ignore specific revisions
  • <?
    //check for a safe username
    function safeuname($name)
    {
    	if (strlen($name) < 2) return FALSE;
    	return ereg("^[a-z][a-z0-9_]*$", $name);
    }
    //check for a valid email address
    function validEmail ($email)
    {
    	global $error;
    	//split user and domain
    	list($user,$domain) = explode("@", $email);
    	// check for bad characters, and check for zero length user & domain
    	if(!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$",$email) or !$user or !$domain )
    	{
    		$error = 'an invalid email address (syntax)';
    		return false;
    	}
    	// Syntax OK
    	
    	// Check for an mail server
    	elseif(!getmxrr($domain,$mx) or !gethostbyname($domain)) 
    	{
    		$error = "no mail servers listed for '$domain'";
    		return false;
    	}
    	else 
    	{
    		// Email address valid from technical point of view
    		return true;
    	}
    }
    
    // Find out if a given user has a blog
    function blogger ($user) {
    	global $BlogDB;
    	$result = $BlogDB->GetAll("select username from users where username='". $user ."'");
    	if (count($result)>0) return true;
    	else return false;
    }
    
    ?>