Advertisement
Guest User

Untitled

a guest
Aug 15th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.16 KB | None | 0 0
  1. <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  2.  
  3. class Register extends CI_Controller {
  4.  
  5.     private $base_url = FALSE;
  6.  
  7.     function index() {
  8.         $data['title'] = "The Star 8 | Register new account";
  9.         $data['base_url'] = base_url();
  10.         $data['errors'] = FALSE;
  11.         $this->load->view('register_view', $data);
  12.     }
  13.  
  14.     function save() {
  15.         $this->load->model('users'); // LOAD MODEL 'USERS'
  16.  
  17.         // $_POST['username']; security == 0
  18.         $username = $this->input->post('username');
  19.         $password = $this->input->post('password');
  20.         $confirm_password = $this->input->post('confirm_password');
  21.         $email = $this->input->post('email');
  22.  
  23.         $username = trim(strtolower($username));
  24.         $password = trim($password);
  25.         $confirm_password = trim($confirm_password);
  26.         $email = trim(strtolower($email));
  27.  
  28.         $errors = array();
  29.         if ($username == '' || strlen($username) < 6) {
  30.             $errors[] = "Please enter username 6 characters";
  31.         }
  32.         if ($password == '' || strlen($password) >= 16) {
  33.             $errors[] = "Please enter password up to 16 characters";
  34.         }
  35.         if ($password != $confirm_password) {
  36.             $errors[] = "Your password do not match";
  37.         }
  38.         if ($email == '' ||
  39.                 !preg_match('/^[_\.0-9a-zA-Z-]+@([0-9a-zA-Z][0-9a-zA-Z-]+\.)+[a-zA-Z.]{2,6}$/i',
  40.                 $email)) {
  41.             $errors[] = "Your email is invalid";
  42.         }
  43.         if ($this->users->is_existed_username($username)) {
  44.             $errors[] = "This username is used by another user";
  45.         }
  46.         if ($errors) {
  47.             /*
  48.             echo "<pre>"; print_r($errors); echo "</pre>";
  49.             */
  50.             $data['title'] = "Register new account";
  51.             $data['base_url'] = base_url();
  52.             $data['errors'] = $errors;
  53.             $this->load->view('register_view', $data);
  54.         } else {
  55.             $password = md5($password);
  56.             $confirm_password = md5($confirm_password);
  57.  
  58.             $data = array(
  59.                 'user_name' => $username,
  60.                 'user_password' => $password,
  61.                 'user_email' => $email,
  62.                 'user_status' => 1
  63.             );
  64.             $this->users->add_user($data); // AND CAN USE INSTANTLY
  65.             redirect(base_url() . 'user/login', 'refresh');
  66.         }
  67.     }
  68.  
  69.     function collect($name = 'John', $age = 20) {
  70.         echo "Your name is " . $name .
  71.             ". Your age is " . $age;
  72.     }
  73.  
  74. }
  75.  
  76. /* End of file register.php */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement