Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- include 'roots/seed.php';
- mysql_connect($dbhost, $dbuser, $dbpass) or die(mysql_error());
- mysql_select_db($dbselect) or die(mysql_error());
- class site
- {
- private static $t = 'template/';
- private static $p = 'pages/';
- public static function load()
- {
- include site::$t.'header.php';
- if(count($_GET) > 0)
- {
- $page = array_keys($_GET);
- $page = $page[0];
- $page .= '.php';
- }
- else
- {
- if(isset($_SESSION['user']))
- {
- $page = 'index.php';
- }
- else
- {
- $page = 'login.php';
- }
- }
- include site::$p.$page;
- include site::$t.'footer.php';
- }
- public static function login()
- {
- if(isset($_POST['login']))
- {
- if(empty($_POST['username']))
- {
- print 'Username field was empty, please try again.';
- return;
- }
- if(empty($_POST['password']))
- {
- print 'Password field was empty, please try again.';
- return;
- }
- print '<center><img src="images/loader.gif" /> submitting information..</center>';
- $encrypt = sha1(strtoupper($_POST['username'].':'.$_POST['password']));
- $q = mysql_query("SELECT * FROM users WHERE user = '$_POST[username]' AND password = '$encrypt'") or die(mysql_error());
- if(!mysql_num_rows($q) == 0)
- {
- $_SESSION['user'] = $_POST['username'];
- echo $_SESSION['user'];
- }
- else
- {
- print 'Couldn\'t log you in, please try again.';
- return;
- }
- }
- }
- public static function is_valid_email($email)
- {
- $qtext = '[^\\x0d\\x22\\x5c\\x80-\\xff]';
- $dtext = '[^\\x0d\\x5b-\\x5d\\x80-\\xff]';
- $atom = '[^\\x00-\\x20\\x22\\x28\\x29\\x2c\\x2e\\x3a-\\x3c'.
- '\\x3e\\x40\\x5b-\\x5d\\x7f-\\xff]+';
- $quoted_pair = '\\x5c\\x00-\\x7f';
- $domain_literal = "\\x5b($dtext|$quoted_pair)*\\x5d";
- $quoted_string = "\\x22($qtext|$quoted_pair)*\\x22";
- $domain_ref = $atom;
- $sub_domain = "($domain_ref|$domain_literal)";
- $word = "($atom|$quoted_string)";
- $domain = "$sub_domain(\\x2e$sub_domain)*";
- $local_part = "$word(\\x2e$word)*";
- $addr_spec = "$local_part\\x40$domain";
- return preg_match("!^$addr_spec$!", $email) ? true : false;
- }
- public static function register()
- {
- if(isset($_POST['register']))
- {
- if(empty($_POST['username']))
- {
- print 'Username field was empty, please try again.';
- return;
- }
- if(empty($_POST['email']))
- {
- print 'E-mail field was empty, please try again.';
- return;
- }
- if(!site::is_valid_email($_POST['email']))
- {
- print 'E-mail was not valid, please try again.';
- return;
- }
- if(empty($_POST['password']) || empty($_POST['confirmpassword']))
- {
- print 'Password fields were empty, please try again.';
- return;
- }
- if($_POST['password'] != $_POST['confirmpassword'])
- {
- print 'Passwords did not match.';
- return;
- }
- $encrypt = sha1(strtoupper($_POST['username'].':'.$_POST['password']));
- $q = mysql_query("INSERT INTO users SET user = '$_POST[username]', password = '$encrypt', email = '$_POST[email]'");
- if(!q)
- {
- print 'Something went wrong, please try again.';
- return;
- }
- else
- {
- print '<center><img src="images/loader.gif" /> creating account..</center>';
- sleep(1);
- print '<center>Account was created, redirecting you..';
- sleep(1);
- header("Location:./");
- }
- }
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement