Misschien een hele domme vraag maar iemand die ik ken is bezig met een script maar daar mist een registratie bij, nu weet diegene het zelf niet te maken en ik zal het ook niet weten.


/*UPDATE WIZARD */
if (isset($_POST['uname'])){

	$prof ='';
	$username = trim($_POST['uname']);
	$email = trim($_POST['email']);
	$pwd1 = trim($_POST['pwd1']);
	$pwd2 = trim($_POST['pwd2']);
	$v_code  = md5(uniqid($username.'arikkerenregister', true));// add a secret word
	
		/* update ip address */
		$ip_addr = get_client_ip();
		$ip_addr = $db->escape_string($ip_addr );
	if($meta['forbid_ip'] == 'enabled'){
		$ip_data = get_stat("SELECT count(*) as num FROM users WHERE ip_address ='".$ip_addr."' and web_id= ".$site_id."");
		if ($ip_data->num != 0 ){
			$r = array('status'=> 'error', 'text'=>$_t['ip_is_register_to_other_user']);
			debug($r,config::debug);
		}
	
	}
	/* end of update */
	
	/* update 18 years */
	
	$date_epoch = strtotime($_POST['year'].'-'.$_POST['month'].'-'.$_POST['day']);
	if( (time() - $date_epoch ) < 567648000 ){
		$r = array('status'=> 'error', 'text'=>"You are under 18 years old" ,"reload"=>"https://www.google.com/");
			debug($r,config::debug);
	}
	/* end */
	
	if (strlen($username)  <= 2 ){
		$r = array('status'=> 'error', 'text'=>$_t['uname_min_err'] );
		debug($r,config::debug);
	}else{
		$sql= "SELECT username from users WHERE username='".$db->escape_string($username)."'";
		$result = $db->query($sql);
			if ( $result->num_rows >= 1){
					$r = array('status'=> 'error', 'text'=>$_t['uname_duplicate_err'] );
					debug($r,config::debug);
				}
		$sql= "SELECT profile_name from user_profiles WHERE profile_name='".$db->escape_string($username)."' ";
		$result = $db->query($sql);
			if ( $result->num_rows >= 1){
					$r = array('status'=> 'error', 'text'=>$_t['uname_duplicate_err'] );
					debug($r,config::debug);
				}		
		
	}
	
	if(!filter_var($email, FILTER_VALIDATE_EMAIL)){
		$r = array('status'=> 'error', 'text'=>$_t['email_not_valid'] );
		debug($r,config::debug);
	}else{
		$sql= "SELECT email from users WHERE email='".$db->escape_string($email)."'";
		$result = $db->query($sql);
			if ( $result->num_rows >= 1){
					$r = array('status'=> 'error', 'text'=>$_t['email_duplicate_err'] );
					debug($r,config::debug);
				}
	}
	
	if (strlen($pwd1)  <= 5 ){
		$r = array('status'=> 'error', 'text'=>$_t['password_length_err'] );
		debug($r,config::debug);	
	}elseif ($pwd1 !== $pwd2){
		$r = array('status'=> 'error', 'text'=>$_t['password_not_match'] );
		debug($r,config::debug);
	}
	
	/* check for proper site */
	$meta_slave = get_slave_meta($site_id);
	$meta		= array_merge($meta,$meta_slave);
	/* end of changes */
	
	$sql= "INSERT INTO users (`username`, `role`, `password`, `state`, `email`, `credit`, `time_registered`, `is_online`, `verify_code`, ip_address, web_id) 
		VALUES ('".$db->escape_string($username)."', 'user', '".$db->escape_string(md5($pwd1))."', 
		'active', '".$db->escape_string($email)."', '".$meta['init_credit']."',NOW(), '0', '".$db->escape_string($v_code)."', '".$ip_addr."','".$site_id."' )";
	
	if ($db->query($sql)){
	
		$uid  = $db->insert_id;
		$land = explode('-',$_POST['province'],2);
		
		$fname  = strtolower($username);
		$email_f = preg_replace('/[^a-zA-Z0-9-_]/','',$fname );
		
		
		
		/* CREATE A PROFILE DIRECTLY*/
	$sql= "INSERT INTO user_profiles (`user_id`, `profile_name`, `gender`, `birthdate`,  `province`, `nation`, `length`, `physique`, `eye_color`, `hair_color`, `education`, `smoking`, `piercing`, `tattoo`, `aboutme`, `aboutyou`, `is_fake`,  `looking_for`, `relationship`, `etnic`, `pubic_hair`,`fictional_email`,  `cup_size`) VALUES (
	'".$db->escape_string($uid)."',
	'".$db->escape_string(strip_tags($username))."',
	'".$db->escape_string($_POST['gender'])."',
	'".$db->escape_string($_POST['year'].'-'.$_POST['month'].'-'.$_POST['day'])."',
	'".$db->escape_string($land[1])."',
	'".$db->escape_string($land[0])."',
	'".$db->escape_string(strip_tags($_POST['lengte']))."',
	'".$db->escape_string($_POST['fisik'])."',
	'".$db->escape_string($_POST['eye_color'])."',
	'".$db->escape_string($_POST['hair_color'])."',
	'".$db->escape_string($_POST['training'])."',
	'".$db->escape_string($_POST['smoke'])."',
	'".$db->escape_string($_POST['biseksual'])."',
	'".$db->escape_string($_POST['tattoo'])."',
	'".$db->escape_string(strip_tags(($_POST['overme'])))."',
	'".$db->escape_string(strip_tags(($_POST['overyou'])))."',
	'0',
	'".$db->escape_string($_POST['gender_in'])."',
	'".$db->escape_string($_POST['relatie'])."',
	'".$db->escape_string($_POST['huidskleur'])."',
	'".$db->escape_string($_POST['pubic_hair'])."',
	'".$db->escape_string($email_f)."',
	'".$db->escape_string($_POST['cupmaat'])."')";
	
	
	
	if ( !$db->query($sql)){
		$prof =$_t['failed_create_profile']." ". $db->error;
	}else{
		$f_id  = $db->insert_id;
		if(file_exists(__DIR__.'/images/'.$f_id.'_150x150_0.jpg'))
			unlink(__DIR__.'/images/'.$f_id.'_150x150_0.jpg');
				
		if(file_exists(__DIR__.'/images/'.$f_id.'_300x300_0.jpg'))
			unlink(__DIR__.'/images/'.$f_id.'_300x300_0.jpg');
				
		if(file_exists(__DIR__.'/images/'.$f_id.'_original_0.jpg'))
			unlink(__DIR__.'/images/'.$f_id.'_original_0.jpg');
			
		/* for interest */
		
		/* add this user to site relation */
		$db->query("insert into  site_profile_relation  (site_id, profile_id, is_fake_user) VALUES ('".$site_id."', '".$f_id."',0 )");
		
		if(isset($_POST['interest'] )){
		$db->query("delete from user_relation where type='interest' and id_profile='".$f_id."'");
		foreach ($_POST['interest'] as $interest){
			$db->query("INSERT INTO  user_relation (`type`, `id_profile`, `id_interest`) VALUES ('interest', '".$f_id."', '".$db->escape_string($interest)."')");
		}
		}
		
		$image2 ='img/no_image_'.$_POST['gender'].'.jpg';
		$allowedExts = array("gif", "jpeg", "jpg", "png");
		if (isset($_FILES["ppicture"]) ){

		$extension = end(explode(".", $_FILES["ppicture"]["name"]));
	
		if ((($_FILES["ppicture"]["type"] == "image/gif")|| ($_FILES["ppicture"]["type"] == "image/jpeg")|| ($_FILES["ppicture"]["type"] == "image/jpg")|| ($_FILES["ppicture"]["type"] == "image/pjpeg")|| ($_FILES["ppicture"]["type"] == "image/x-png")|| ($_FILES["ppicture"]["type"] == "image/png"))&& ($_FILES["ppicture"]["size"] < 2000000)&& in_array($extension, $allowedExts))
		{
			if ($_FILES["ppicture"]["error"] > 0){
			$r = array('status'=> 'error', 'text'=>"fout: " . $_FILES["file"]["error"]);
			debug($r,config::debug);
			}else{
				$source_path = $_FILES['ppicture']['tmp_name'];
				$image2 = create_image($source_path, $f_id.'_150x150_0.jpg', 150, 150);
				
				if ($image2 !==''){
					$db->query("UPDATE user_profiles set profile_image = '".$image2 ."' where profile_id='".$f_id."' ");
					create_image($source_path, $f_id.'_300x300_0.jpg', 300, 300);
					move_uploaded_file($source_path,'images/'.$f_id.'_original_0.jpg');
					$image = $image2 ;
				
				}
				
			}
  		}
	
		}
		
		
		/*SIGN IN AUTOMATICALLY*/
		$_SESSION['user_id'] = $uid;
		$_SESSION['username'] = $username;
		$_SESSION['role'] = 'user';
		$_SESSION['profile_id'] = $f_id ;
		$_SESSION['image'] = $image2;
		$_SESSION['imagexxx'] = $image2;
		
		
		}
		/*END OF */
		
		/* REGISTER MINI VERSION */
			if(isset($_POST['dest_mini']) and $_POST['dest_mini'] !== '' ){
					if($_POST['msg_mini']){						
							stuur_mail($f_id, $_POST['dest_mini'],$_POST['msg_mini'] );
					}
			
			}
			
		/* END */
		
		/* SEND WELCOME MESSAGE */
		
			$mess = get_stat("SELECT * FROM `auto_responder` WHERE type='welcome_message' and (site_id = '".$site_id."' or site_id=0)  order by rand() LIMIT 1");
			if(!empty($mess)){
			
			$mess->content = str_replace('%profilename%',$username, $mess->content);
			
			$sql = "INSERT INTO `messages` (`from`, `to`, `message`, `has_attachment`, `time_sending`, `mark`) VALUES (
			'1',
			'".$f_id ."',
			'".$db->escape_string($mess->content)."',0,NOW(),'unread')";
			$db->query($sql);
			
			}
		/* END OF  */
		
		
		$param = array('type'=>'account_activation','username'=>$username, "password" =>$pwd1, 'siteid'=>$site_id ,'contact_url'=>$uri.'contact.php');
		kirim_email($email, $param, $meta);
				
		$r = array('status'=> 'success', 'text'=>$_t['register_success']);
	}else{
		$r = array('status'=> 'error', 'text'=>$_t['register_failed'] );
	}

	debug($r,config::debug);
			
}

/* END OF UPDATE */


Ik weet dat de code een beetje overdreven groot is, dit is wat in ajax.php staat? Maar hoe krijgt hij er een registratie formulier bij?

Groetjes
Even een simpel voorbeeld:

<?php
// controleer of user al bestaat
$result = $db->query("SELECT username FROM users WHERE username='Pietje'");
if($result->num_rows > 0) {
echo "Gebruiker bestaat al";
} else {
echo "Gebruiker is nog beschikbaar";
}
?>

Het wachtwoord zou ik niet meer met md5() doen. Dat is hopeloos ouderwets.
Gebruik liever password_hash() om een wachtwoord te genereren en password_verify() om deze te controleren.

Reageren