Don't like ads? PRO users don't see any ads ;-)
Guest

Register Handler/Class

By: a guest on Apr 28th, 2012  |  syntax: PHP  |  size: 2.98 KB  |  hits: 26  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. <?php
  2. class Register
  3. {
  4.     public static function HandleRegister()
  5.     {
  6.         global $db;
  7.         global $User;
  8.         global $Session;
  9.        
  10.         if(isset($_POST['username'], $_POST['password'], $_POST['email'], $_POST['realname']))
  11.         {
  12.             $username = $_POST['username'];
  13.             $password = hash_string($_POST['password']);
  14.             $email = $_POST['email'];
  15.             $realname = $_POST['realname'];
  16.             $figure = DEFAULT_LOOK;
  17.             $ip = USER_IP;
  18.            
  19.                         if($User->CheckBan($_SERVER['REMOTE_ADDR']))
  20.                         {
  21.                                 die('You\'re IP banned, go away.');
  22.                                 exit;
  23.                         }
  24.                        
  25.             if(empty($username) || empty($password) || empty($email) || empty($realname))
  26.             {
  27.                 redirect('?error=fields');
  28.                 exit;
  29.             }
  30.            
  31.             if($User->GetData('username', $username) != false)
  32.             {
  33.                 redirect('?error=username');
  34.                 exit;
  35.             }
  36.            
  37.             $filter = preg_replace("/[^a-z\d\-=\?!@:\.]/i", "", $username);
  38.             if($filter != $username)
  39.             {
  40.                 redirect('?error=invalid');
  41.                 exit;
  42.             }
  43.  
  44.             $filter = preg_replace("[!\?@:\\\.]", "", $username);
  45.             if($filter != $username)
  46.             {
  47.                 redirect('?error=invalid');
  48.                 exit;
  49.             }
  50.  
  51.  
  52.             // Create the user record
  53.             $User->createUser($username, $password, $email, $realname, $figure);
  54.            
  55.             // Get the user's ID
  56.             $query = $db->query('SELECT `id` FROM `users` WHERE `username` = "' . $username . '"');
  57.             $id = $db->result($query);
  58.            
  59.             // Insert the user_info.
  60.             $db->query("INSERT INTO `user_info` (`user_id` ,`bans` ,`cautions` ,`reg_timestamp` ,`login_timestamp` ,`cfhs` ,`cfhs_abusive`)VALUES ('" . $id . "',  '0',  '0',  '" . time() . "',  '0',  '0',  '0');");
  61.            
  62.             // Register the session & log it
  63.             $Session->Set('username', $username);
  64.            
  65.             // Redirect the user to the "me" page.
  66.             redirect('me.php');
  67.            
  68.         }
  69.     }
  70.     public static function ErrorHandler()
  71.     {
  72.         if(isset($_GET['error']))
  73.         {
  74.             echo "<div id='error'>";
  75.             switch($_GET['error'])
  76.             {
  77.                 case 'passwords':
  78.                     echo "Both passwords are required.";
  79.                     break;
  80.                
  81.                 case 'username':
  82.                     echo "That username is already in use.";
  83.                     break;
  84.                
  85.                 case 'fields':
  86.                     echo "All fields are required.";
  87.                     break;
  88.  
  89.                 case 'invalid':
  90.                     echo "There are invalid characters in your username!";
  91.                     break;
  92.             }
  93.             echo "</div>";
  94.         }
  95.     }
  96. }