Advertisement
Guest User

Untitled

a guest
Jun 9th, 2017
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.36 KB | None | 0 0
  1. <?php
  2. include 'roots/seed.php';
  3. mysql_connect($dbhost, $dbuser, $dbpass) or die(mysql_error());
  4. mysql_select_db($dbselect) or die(mysql_error());
  5.  
  6. class site
  7. {
  8.    
  9.     private static $t = 'template/';
  10.     private static $p = 'pages/';  
  11.  
  12.     public static function load()
  13.     {
  14.  
  15.         include site::$t.'header.php';
  16.        
  17.         if(count($_GET) > 0)
  18.         {  
  19.             $page = array_keys($_GET);
  20.             $page = $page[0];
  21.             $page .= '.php';
  22.         }
  23.         else
  24.         {
  25.             if(isset($_SESSION['user']))
  26.             {
  27.                 $page = 'index.php';
  28.             }
  29.             else
  30.             {
  31.                 $page = 'login.php';
  32.             }
  33.         }
  34.        
  35.         include site::$p.$page;
  36.         include site::$t.'footer.php';
  37.     }
  38.  
  39.     public static function login()
  40.     {
  41.         if(isset($_POST['login']))
  42.         {
  43.             if(empty($_POST['username']))
  44.             {
  45.                 print 'Username field was empty, please try again.';
  46.                 return;
  47.             }
  48.  
  49.             if(empty($_POST['password']))
  50.             {
  51.                 print 'Password field was empty, please try again.';
  52.                 return;
  53.             }
  54.  
  55.             print '<center><img src="images/loader.gif" /> submitting information..</center>';
  56.  
  57.             $encrypt = sha1(strtoupper($_POST['username'].':'.$_POST['password']));
  58.             $q = mysql_query("SELECT * FROM users WHERE user = '$_POST[username]' AND password = '$encrypt'") or die(mysql_error());
  59.            
  60.             if(!mysql_num_rows($q) == 0)
  61.             {
  62.                 $_SESSION['user'] = $_POST['username'];
  63.                 echo $_SESSION['user'];
  64.             }
  65.             else
  66.             {
  67.                 print 'Couldn\'t log you in, please try again.';
  68.                 return;
  69.             }
  70.         }
  71.     }
  72.    
  73.     public static function is_valid_email($email)
  74.     {
  75.         $qtext = '[^\\x0d\\x22\\x5c\\x80-\\xff]';
  76.         $dtext = '[^\\x0d\\x5b-\\x5d\\x80-\\xff]';
  77.         $atom = '[^\\x00-\\x20\\x22\\x28\\x29\\x2c\\x2e\\x3a-\\x3c'.
  78.                     '\\x3e\\x40\\x5b-\\x5d\\x7f-\\xff]+';
  79.         $quoted_pair = '\\x5c\\x00-\\x7f';
  80.         $domain_literal = "\\x5b($dtext|$quoted_pair)*\\x5d";
  81.         $quoted_string = "\\x22($qtext|$quoted_pair)*\\x22";
  82.         $domain_ref = $atom;
  83.         $sub_domain = "($domain_ref|$domain_literal)";
  84.         $word = "($atom|$quoted_string)";
  85.         $domain = "$sub_domain(\\x2e$sub_domain)*";
  86.         $local_part = "$word(\\x2e$word)*";
  87.         $addr_spec = "$local_part\\x40$domain";
  88.  
  89.         return preg_match("!^$addr_spec$!", $email) ? true : false;
  90.     }
  91.    
  92.     public static function register()
  93.     {
  94.         if(isset($_POST['register']))
  95.         {
  96.             if(empty($_POST['username']))
  97.             {
  98.                 print 'Username field was empty, please try again.';
  99.                 return;
  100.             }
  101.            
  102.             if(empty($_POST['email']))
  103.             {
  104.                 print 'E-mail field was empty, please try again.';
  105.                 return;
  106.             }
  107.            
  108.             if(!site::is_valid_email($_POST['email']))
  109.             {
  110.                 print 'E-mail was not valid, please try again.';
  111.                 return;
  112.             }
  113.            
  114.             if(empty($_POST['password']) || empty($_POST['confirmpassword']))
  115.             {
  116.                 print 'Password fields were empty, please try again.';
  117.                 return;
  118.             }
  119.            
  120.             if($_POST['password'] != $_POST['confirmpassword'])
  121.             {
  122.                 print 'Passwords did not match.';
  123.                 return;
  124.             }
  125.            
  126.             $encrypt = sha1(strtoupper($_POST['username'].':'.$_POST['password']));
  127.             $q = mysql_query("INSERT INTO users SET user = '$_POST[username]', password = '$encrypt', email = '$_POST[email]'");
  128.            
  129.             if(!q)
  130.             {
  131.                 print 'Something went wrong, please try again.';
  132.                 return;
  133.             }
  134.             else
  135.             {
  136.                 print '<center><img src="images/loader.gif" /> creating account..</center>';
  137.                 sleep(1);
  138.                 print '<center>Account was created, redirecting you..';
  139.                 sleep(1);
  140.                 header("Location:./");
  141.             }
  142.            
  143.         }
  144.     }
  145.  
  146. }
  147. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement