Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
- class Register extends CI_Controller {
- private $base_url = FALSE;
- function index() {
- $data['title'] = "The Star 8 | Register new account";
- $data['base_url'] = base_url();
- $data['errors'] = FALSE;
- $this->load->view('register_view', $data);
- }
- function save() {
- $this->load->model('users'); // LOAD MODEL 'USERS'
- // $_POST['username']; security == 0
- $username = $this->input->post('username');
- $password = $this->input->post('password');
- $confirm_password = $this->input->post('confirm_password');
- $email = $this->input->post('email');
- $username = trim(strtolower($username));
- $password = trim($password);
- $confirm_password = trim($confirm_password);
- $email = trim(strtolower($email));
- $errors = array();
- if ($username == '' || strlen($username) < 6) {
- $errors[] = "Please enter username 6 characters";
- }
- if ($password == '' || strlen($password) >= 16) {
- $errors[] = "Please enter password up to 16 characters";
- }
- if ($password != $confirm_password) {
- $errors[] = "Your password do not match";
- }
- if ($email == '' ||
- !preg_match('/^[_\.0-9a-zA-Z-]+@([0-9a-zA-Z][0-9a-zA-Z-]+\.)+[a-zA-Z.]{2,6}$/i',
- $email)) {
- $errors[] = "Your email is invalid";
- }
- if ($this->users->is_existed_username($username)) {
- $errors[] = "This username is used by another user";
- }
- if ($errors) {
- /*
- echo "<pre>"; print_r($errors); echo "</pre>";
- */
- $data['title'] = "Register new account";
- $data['base_url'] = base_url();
- $data['errors'] = $errors;
- $this->load->view('register_view', $data);
- } else {
- $password = md5($password);
- $confirm_password = md5($confirm_password);
- $data = array(
- 'user_name' => $username,
- 'user_password' => $password,
- 'user_email' => $email,
- 'user_status' => 1
- );
- $this->users->add_user($data); // AND CAN USE INSTANTLY
- redirect(base_url() . 'user/login', 'refresh');
- }
- }
- function collect($name = 'John', $age = 20) {
- echo "Your name is " . $name .
- ". Your age is " . $age;
- }
- }
- /* End of file register.php */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement