dwlakes

register_new

May 8th, 2022
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.10 KB | None | 0 0
  1. <?php
  2.     ini_set('display_errors', 1);
  3.     ini_set('display_startup_errors', 1);
  4.     error_reporting(E_ALL);
  5.    
  6.     // include function files for his application
  7.     require_once('bookmark_fns.php');
  8.     // create short variable names
  9.     $email=$_POST['email'];
  10.     $username=$_POST['username'];
  11.     $passwd=$_POST['passwd'];
  12.     $passwd2=$_POST['passwd2'];
  13.     // start session which may be needed later
  14.     // start it now because it must go before headers
  15.     session_start();
  16.     try {
  17.         // check forms filled in
  18.         if (!filled_out($_POST)){
  19.             throw new Exception('You have not filled the form out correctly -
  20.            please go back and try again.');
  21.         }
  22.  
  23.         // email address not valid
  24.         if (!valid_email($email)){
  25.             throw new Exception('That is not a valid email address.
  26.            Please go back and try again.');
  27.         }
  28.  
  29.         // passwords not the same
  30.         if ($passwd != $passwd2){
  31.             throw new Exception('The passwords you entered do not match -
  32.            please go back and try again.');
  33.         }
  34.  
  35.         // check password length is ok
  36.         // ok if username truncates, but passwords will get
  37.         // munged if they are too long.
  38.         if ((strlen($passwd) < 6) || (strlen($passwd) > 16)){
  39.             throw new Exception('Your password must be between 6 and 16 characters.
  40.            Please go back and try again.');
  41.         }
  42.  
  43.         // attempt to register
  44.         // this function can also thro an exception
  45.         register($username, $email, $passwd);
  46.         // register session variable
  47.         $_SESSION['valid_user'] = $username;
  48.  
  49.         // provide link to members page
  50.         do_html_header('Registration successful');
  51.         echo 'Your registration was successful. Go to the members page to start setting up your bookmarks!';
  52.         do_html_url('member.php','Go to members page');
  53.  
  54.         // end page
  55.         do_html_footer();
  56.     }catch (Exception $e){
  57.         do_html_header('Problem: ');
  58.         echo $e->getMessage();
  59.         do_html_footer();
  60.         exit;
  61.     }
  62. ?>
Advertisement
Add Comment
Please, Sign In to add comment