PHP:
class xxxxxx{
//Handle Registration
function handle_registration(){
$this->username = $this->registry->get('input')->POST['username'];
$this->password = $this->registry->get('input')->POST['password'];
$this->password2 = $this->registry->get('input')->POST['password2'];
$this->alias = $this->registry->get('input')->POST['alias'];
$this->website = $this->registry->get('input')->POST['website'];
$this->email = $this->registry->get('input')->POST['email'];
$this->sitename = $this->registry->get('input')->POST['sitename'];
$this->location = $this->registry->get('input')->POST['location'];
//Check for isset() and strlen and regex char checks
if(isset($this->username) || isset($this->password) || isset($this->password2) || isset($this->alias) || isset($this->website) || isset($this->email) ){
//Form has been sent
if(strlen($this->username) == 0){$this->register_errors['no_username'] = true;}
if(strlen($this->password) == 0){$this->register_errors['no_password'] = true;}
if(strlen($this->password2) == 0){$this->register_errors['no_password2'] = true;}
if(strlen($this->alias) == 0){$this->register_errors['no_alias'] = true;}
if(strlen($this->website) == 0){$this->register_errors['no_website'] = true;}
if(strlen($this->email) == 0){$this->register_errors['no_email'] = true;}
if(strlen($this->sitename) == 0){$this->register_errors['no_sitename'] = true;}
//Min Len
if(strlen($this->username) != 0 && strlen($this->username) < 6){$this->register_errors['username_too_short'] = true;}
if(strlen($this->password) != 0 && strlen($this->password) < 6){$this->register_errors['password_too_short'] = true;}
if(strlen($this->password2) != 0 && strlen($this->password2)< 6){$this->register_errors['password2_too_short'] = true;}
if(strlen($this->alias) != 0 && strlen($this->alias) < 4){$this->register_errors['alias_too_short'] = true;}
if(strlen($this->sitename) != 0 && strlen($this->sitename) < 4){$this->register_errors['sitename_too_short'] = true;}
//Max Len
if(strlen($this->username) > 32){$this->register_errors['username_too_long'] = true;}
if(strlen($this->password) > 32){$this->register_errors['password_too_long'] = true;}
if(strlen($this->alias) > 32){$this->register_errors['alias_too_long'] = true;}
if(strlen($this->sitename) > 32){$this->register_errors['sitename_too_long'] = true;}
//Location can be defualtized
$this->location = isset($this->location) ? $this->location : "GB"; // defualt to uk !
if(count($this->register_errors) == 0){
//everything is inputted and is the correct lenght
//Check the webiste domain is valid!
$this->website = str_replace('www.','',$this->website); // Remove www. for the below regex
if(!strstr('http://',$this->website)){$this->website = 'http://' . $this->website;} //Adds http:// if not existsing
if(!filter_var($this->website,FILTER_VALIDATE_URL)){$this->register_errors['invalid_website'] = true;}
//Set email back to the domain no HTTP for database insert later
$this->website = str_replace("http://","",$this->website);
//Check the email regex! - Taken from phpBB get_preg_expression()
if(!filter_var($this->email,FILTER_VALIDATE_EMAIL)){$this->register_errors['email_invalid'] = true;}
//Username and email validation
if(!preg_match("/^[a-zA-Z0-9\_]+$/",$this->username)){$this->register_errors['username_invalid'] = true;}
if(!preg_match("/^[a-zA-Z0-9\_]+$/",$this->password)){$this->register_errors['password_invalid'] = true;}
if(!preg_match("/^[a-zA-Z0-9\_\s]+$/",$this->alias)){$this->register_errors['alias_invalid'] = true;}
//Now check see if the passwords match.
if(strcmp($this->password,$this->password2) != 0){$this->register_errors['passwords_no_match'] = true;}
//Do Location validate
if(count($this->register_errors) == 0){
//Proceed to the dabase recorde creation
//Check if email or doman or username is in use !
//EMAIL
$this->sql = "SELECT webmaster_id FROM ".WEBMASTERS_TABLE." WHERE xxxx = '%s'";
$this->sql = sprintf($this->sql,$this->email);
$this->registry->get('database')->query($this->sql);
if($this->registry->get('database')->num_rows() == 0){
//ok so the email is not in use well check the username
$this->sql = "SELECT xxxx FROM ".WEBMASTERS_TABLE." WHERE xxxxx = '%s'";
$this->sql = sprintf($this->sql,$this->username);
$this->registry->get('database')->query($this->sql);
if($this->registry->get('database')->num_rows() == 0){
//No user has got this username just have to check make sure the domain is available
$this->sql = "SELECT xxxx FROM ".SITES_TABLE." WHERE xxxx = '%s'";
$this->sql = sprintf($this->sql,$this->website);
$this->registry->get('database')->query($this->sql);
if($this->registry->get('database')->num_rows() == 0){
//Insert new user and website
/*
Ready for registration
*/
//Buld the queryies
//Need to insert the website first to get teh ID number
$this->site_name_clean = preg_replace("/[^a-zA-Z0-9\_]+/","_",strtolower($this->sitename));
$this->sql_site = "INSERT INTO ".SITES_TABLE." VALUES (NULL,'%s','%s','%s','%s',0,0,0)";
$this->sql_site = sprintf($this->sql_site,$this->sitename,$this->site_name_clean,$this->website,$this->email);
//Insert Sites
$this->registry->get('database')->query($this->sql_site);
$this->siteId = $this->registry->get('database')->getInsertId();
//No we can add the user to the webmasters table !
$this->sql_webmaster = "INSERT INTO ".WEBMASTERS_TABLE." VALUES(NULL,%d,'%s','%s','%s','%s','%s','%s')";
$this->pass_enc = $this->saltString($this->password);
$this->realIp = $this->registry->get('input')->getRealIp();
$this->sql_webmaster = sprintf($this->sql_webmaster,$this->siteId,$this->alias,$this->username,$this->pass_enc,$this->email,$this->location,$this->realIp);
//Insert webmasters
$this->registry->get('database')->query($this->sql_webmaster);
//Send heaers && add a session key for a registration note on the login page!
$this->registry->get('session')->add('session_registered',time());
$this->registry->get('output')->redirect(_WEBMASTERS_ROOT);
}else{
$this->register_errors['website_in_use'] = true;
}
}else{
$this->register_errors['username_in_use'] = true;
}
}else{
$this->register_errors['email_in_use'] = true;
}
}
}
}
}
}
This is a snippet of the registration validation class for my new Webmasters CP and im posting this to show you at what OOP is all about !!!!!!