不承认不同的用户 [英] Not recognising the different users

查看:73
本文介绍了不承认不同的用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,



我对PHP知之甚少,而且我被指派去尝试解决一些在网站上无法解决的问题。该网站主要处理两个不同的用户,一个可以发布文章的交易者和一个可以发布博客的博主。当用户注册成为交易员时,他被注册为博主。我检查了数据库,所有试图注册为交易者的人都被保存为用户。我认为问题在于注册过程方法。我附上了一份代码。由于我的知识非常有限,我不确定是什么问题。你能看一下,告诉我。我愿意接受任何想法和建议。









Hello,

I have little knowledge with PHP and I was assigned to try to fix some of the things that don't work in a website. The website basically deals with two different users, a trader who can post articles and a blogger who can post blogs. When a user registers to become a trader though, he is registered as a blogger. I checked the database and everyone who tried to register as a trader was saved as a user. I think the problem is in the register process method. I attached a copy of the codes. Since my knowledge is very limited, i'm not exactly sure what's wrong. Can you please take a look at it and let me know. I'm open to any thoughts and suggestions.




public function process()
	{
		$date = date('Y-m-d');
		$userid = uniqid();
		$captchaError = '';
		if($this->input->post('Submit'))
		{
//---------------------------------FORM VALIDATION STARTS HERE---------------------------------
			$this->form_validation->set_error_delimiters('', '');
			$this->form_validation->set_rules('fname', 'Full name','required');
			$this->form_validation->set_rules('email', 'Email', 'required|valid_email|is_unique[tbl_user.email]');
			$this->form_validation->set_rules('password', 'password', 'trim|required|min_length[6]|matches[cpassword]');
			$this->form_validation->set_rules('cpassword', 'Password confirmation', 'required');
			$this->form_validation->set_rules('mycheck[]', 'Buyer or Supplier','required');
			$this->form_validation->set_rules('material[]', 'materials','required');
			$this->form_validation->set_rules('company', 'Company name', 'required');
			$this->form_validation->set_rules('cname', 'Contact name','required');
			$this->form_validation->set_rules('cemail', 'Contact email', 'required|valid_email');
			$this->form_validation->set_rules('nation', 'Country', 'required');
			$this->form_validation->set_rules('city', 'City','required');
			$this->form_validation->set_rules('fax');
			$this->form_validation->set_rules('mobile');
			$this->form_validation->set_rules('phone');
			$this->form_validation->set_rules('website');
			$this->form_validation->set_rules('address');
			$this->form_validation->set_rules('zip');
			$this->form_validation->set_rules('content', 'Tell something about urself', 'required');
			$this->form_validation->set_rules('captchaText', 'captcha text', 'required');
//-----------------------------------FORM VALIDATION ENDS HERE--------------------------------------


//------------------------------------CAPTCHA CHECK------------------------------------------
			if($this->input->post('captchaText'))
			{
				$expiration = time()-7200; // Two hour limit
				$this->db->query("DELETE FROM captcha WHERE captcha_time < ".$expiration);

			// Then see if a captcha exists:
				$sql = "SELECT COUNT(*) AS count FROM captcha WHERE word = ? AND ip_address = ? AND captcha_time > ?";
				$binds = array($_POST['captchaText'], $this->input->ip_address(), $expiration);
				$query = $this->db->query($sql, $binds);
				$row = $query->row();

				if ($row->count == 0)
				{
    			$captchaError =  "You must submit the word that appears in the image";
				}
			}
//--------------------------------------CAPTCHA CHECK ENDS HERE----------------------------

//----------------------------------FORM VALIDATION RETURN ERRORS---------------------------
			if ($this->form_validation->run() == FALSE || $captchaError!='')
			{
			$data['captcha'] = $this->getCaptcha();
			$data['captchaError'] = $captchaError;
			$data['pageTitle']='Registration | Error';
			$this->load->view('register-trader',$data);
			}
//-----------------------------------------------END---------------------------------------

//---------------------------------------INSERT DATA INTO DATABASE-----------------------
			else
			{
			if($this->input->post('material'))
				{
				$material = '';
				foreach($this->input->post('material') as $value)
				{
				$material.= $value.',';
				}
			$material = rtrim($material,',');
			}
			$mycheck = $this->input->post('mycheck');
			$mycheckOne = '';
			$mycheckTwo = '';
			if(!empty($mycheck[0])){$mycheckOne = $mycheck[0];}
			if(!empty($mycheck[1])){$mycheckTwo = $mycheck[1];}
			$config['file_name'] = uniqid(); 
			$config['upload_path'] = UP_PATH;
    		$config['allowed_types'] = 'gif|jpg|png';
    		$config['max_size'] = '1000';
    		$config['max_width']  = '1024';
    		$config['max_height']  = '768';
   			$this->load->library('upload', $config);
			if ( ! $this->upload->do_upload('userfile1'))
			{				
        		$error = $this->upload->display_errors();
				$data = array(
	              'supplier'=>$mycheckOne,
				  'buyer'=>$mycheckTwo,
				  'title'=>$this->input->post('company'),
	              'cname'=>$this->input->post('cname'),
				  'material'=>$material,
				  'email'=>$this->input->post('email'),
				  'phone'=>$this->input->post('phone'),
				  'fax'=>$this->input->post('name'),
				  'mobile'=>$this->input->post('mobile'),
	              'web'=>$this->input->post('website'),
				  'country'=>$this->input->post('nation'),
				  'city'=>$this->input->post('city'),
				  'address'=>$this->input->post('address'),
				  'zip'=>$this->input->post('zip'),
	              'content'=>$this->input->post('content'),
				  'date'=>$date,
				  'userid'=>$userid,
	              'status'=>0
	            );
				
	       	}   
   			else
    		{
				$data = array('upload_data' => $this->upload->data()); 
				$filepath = $data['upload_data']['file_name'];
				$config['image_library'] = 'gd2';
				$config['source_image'] = UP_PATH.$filepath;
				$config['new_image'] = UP_PATH.'thumbs/';
				$config['create_thumb'] = TRUE;
				$config['thumb_marker'] = '';
				$config['maintain_ratio'] = TRUE;
				$config['width'] = 75;
				$config['height'] = 50;
				$this->load->library('image_lib', $config);
				$this->image_lib->resize();
				
				$data = array(
	              'supplier'=>$mycheckOne,
				  'buyer'=>$mycheckTwo,
				  'title'=>$this->input->post('company'),
	              'cname'=>$this->input->post('cname'),
				  'material'=>$material,
				  'email'=>$this->input->post('email'),
				  'phone'=>$this->input->post('phone'),
				  'fax'=>$this->input->post('fax'),
				  'mobile'=>$this->input->post('mobile'),
	              'web'=>$this->input->post('website'),
				  'country'=>$this->input->post('nation'),
				  'city'=>$this->input->post('city'),
				  'address'=>$this->input->post('address'),
				  'zip'=>$this->input->post('zip'),
	              'content'=>$this->input->post('content'),
				  'image'=>$filepath,
				  'date'=>$date,
				  'userid'=>$userid,
	              'status'=>0
				  );
				
			}	
	    	$this->db->insert(TBL_CLA,$data);
	    	
			$log_type = 'trader';
			$password = do_hash($this->input->post('password'));
			$dataOne = array(
	              'password'=>$this->security->xss_clean($password),
				  'fname'=>$this->security->xss_clean($this->input->post('fname')),
	              'email'=>$this->security->xss_clean($this->input->post('email')),
				  'log_type'=>$log_type,
				  'userid'=>$userid,
				  'status'=>0,
				  'date'=>$date,
				  'active'=>1
				  );
			$this->db->insert(TBL_USE,$dataOne);
			
			$this->session->set_userdata('fname', $this->input->post('fname'));
			redirect(base_url().'register/activate');
			}
			}
			if($this->input->post('Login'))
			{
//---------------------------------FORM VALIDATION STARTS HERE---------------------------------
			$this->form_validation->set_error_delimiters('', '');
			$this->form_validation->set_rules('fname', 'Full name','required');
			$this->form_validation->set_rules('email', 'Email', 'required|valid_email|is_unique[tbl_user.email]');
			$this->form_validation->set_rules('password', 'password', 'trim|required|min_length[6]|matches[cpassword]');
			$this->form_validation->set_rules('cpassword', 'Password confirmation', 'required');
			$this->form_validation->set_rules('captchaText', 'captcha text', 'required');
//-----------------------------------FORM VALIDATION ENDS HERE--------------------------------------


//------------------------------------CAPTCHA CHECK------------------------------------------
			if($this->input->post('captchaText'))
			{
				$expiration = time()-7200; // Two hour limit
				$this->db->query("DELETE FROM captcha WHERE captcha_time < ".$expiration);

			// Then see if a captcha exists:
				$sql = "SELECT COUNT(*) AS count FROM captcha WHERE word = ? AND ip_address = ? AND captcha_time > ?";
				$binds = array($_POST['captchaText'], $this->input->ip_address(), $expiration);
				$query = $this->db->query($sql, $binds);
				$row = $query->row();

				if ($row->count == 0)
				{
    			$captchaError =  "You must submit the word that appears in the image";
				}
			}
//--------------------------------------CAPTCHA CHECK ENDS HERE----------------------------

//----------------------------------FORM VALIDATION RETURN ERRORS---------------------------
			if ($this->form_validation->run() == FALSE || $captchaError!='')
			{
			$data['captcha'] = $this->getCaptcha();
			$data['captchaError'] = $captchaError;
			$data['pageTitle']='Registration | Error';
			$this->load->view('register-blogger',$data);
			}
//-----------------------------------------------END---------------------------------------

//---------------------------------------INSERT DATA INTO DATABASE-----------------------
			else
			{
			
			$date = date('Y-m-d');
			$log_type = 'blogger';
			$password = do_hash($this->input->post('password'));
			$dataOne = array(
	              'password'=>$this->security->xss_clean($password),
				  'fname'=>$this->security->xss_clean($this->input->post('fname')),
	              'email'=>$this->security->xss_clean($this->input->post('email')),
				  'log_type'=>$log_type,
				  'userid'=>$userid,
				  'status'=>0,
				  'date'=>$date,
				  'active'=>0
				  );
			$this->db->insert(TBL_USE,$dataOne);
			$data['link'] = 'http://www.arabrecycling.org/activate/created/'.$userid;
			$data['name'] = $this->input->post('fname');
			$message = $this->load->view('includes/activate',$data, TRUE);
			$subject = 'Account Activation';
			$fromTest = 'The Arab Recycling Initiative';
			$this->userRegEmail('info@arabrecycling.org',$this->input->post('email'),$message,$subject,$fromTest);
			$this->session->set_userdata('fname', $this->input->post('fname'));
			redirect(base_url().'register/activate');
			}
			}
		
	   
	}
//-------------------------------------------------------CAPTCHA CREATION STARTS HERE------------------------
	public function getCaptcha(){
		
			$this->load->library('common');
			$this->common = new common();
		
			$this->load->helper('captcha');
			$vals = array(
    		'word' => $this->common->GetRandomCaptchaText(8),
			'img_path' => './captcha/',
   		 	'img_url' => base_url().'captcha/',
    		'font_path' => base_url().'system/fonts/Candice.ttf',
    		'img_width' => '150',
    		'img_height' => 30,
    		'expiration' => 7200
    		);

			$cap = create_captcha($vals);
		
			$data = array(
    		'captcha_time' => $cap['time'],
    		'ip_address' => $this->input->ip_address(),
    		'word' => $cap['word']
    		);

			$query = $this->db->insert_string('captcha', $data);
			$this->db->query($query);

			return $cap['image'];
	}
//--------------------------------------------------------CAPTCHA CREATION ENDS HERE------------------------------------------------
//--------------------------------------------------------CONFIGURING EMAIL------------------------------------------------
		public function userRegEmail($from,$to,$message,$subject,$fromTest){
			 $email_config['protocol'] = 'mail';
			 $email_config['mailtype'] = 'html';
   			 $this->email->initialize($email_config);

   			 $this->email->from($from, $fromTest);
   			 $this->email->to($to);         
   			 $this->email->subject($subject);
   			 $this->email->message($message); 
   			 $this->email->send();
    }
    
    
//--------------------------------------------------------EMAIL CONFIGURATION ENDS HERE------------------------------------------------

推荐答案

date = date('Y-m-d');
\t\t
date = date('Y-m-d');


userid = uniqid();
\t\t
userid = uniqid();


captchaError = '';
\t\tif(
captchaError = ''; if(


这篇关于不承认不同的用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆