[REQ] Basic Register Script

This is guide mostly for website tools and code, for example CMS or registration scripts.
There can also be tools.

Moderators: osRose dev team, ospRose dev team, osiRose dev team, Moderators

[REQ] Basic Register Script

Postby matty13 on Sun Feb 17, 2008 1:25 pm

Does anyone have a basic register script to work with osRose?
matty13
Jelly Bean
Jelly Bean
 
Posts: 26
Joined: Sun Sep 02, 2007 11:58 pm

Re: [REQ] Basic Register Script

Postby Flik on Sun Feb 17, 2008 2:49 pm

User avatar
Flik
Smoulie
Smoulie
 
Posts: 49
Joined: Mon Sep 10, 2007 5:05 pm

Re: [REQ] Basic Register Script

Postby Rifke on Mon Feb 18, 2008 6:15 pm

Comments are welcome

  1.  
  2. <?php
  3. # Written by Rifke (mitch.rifke@telenet.be)
  4. # Written for osrose community
  5. # You can use or distrubute it as long as you leave credits
  6. ?>
  7. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  8. <html xmlns="http://www.w3.org/1999/xhtml">
  9. <head>
  10. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  11. <title>Registration</title>
  12. </head>
  13.  
  14. <body>
  15. <?php
  16. // Settings - start [Cut HERE]
  17. // you can copy this part into your config file if you have one, else edit it here
  18. $Setting['Age_Restriction'] = true// Required to fill in a age!
  19. $Setting['Permitted_Age'] = 16;         // Permitted age.
  20. $Setting['Require_Email'] = true;       // Required to fill in a email addres!
  21. $Setting['MySQL_Host'] = 'localhost';   // MySQL host
  22. $Setting['MySQL_Port'] = '3306';        // MySQL port
  23. $Setting['MySQL_User'] = 'user';        // MySQL user
  24. $Setting['MySQL_Pass'] = 'pass';        // MySQL pass
  25. $Setting['MySQL_mndb'] = 'osrose';      // MySQL database
  26. // Settings - end [Cut HERE]
  27.  
  28. $Submitted = false// used to see if a form is submitted
  29. if ( ($_SERVER['REQUEST_METHOD'] == 'POST') && ($_POST['Submit'] == 'Submit') ) {
  30.     function protect($string) {
  31.         if ( get_magic_quotes_gpc() == 1 ) return $string;
  32.         else return mysql_real_escape_string($string);
  33.     }
  34.     // validation
  35.     if ( strlen(trim($_POST['username'])) > 24 ) $Error[] = 'Please fill in a username with less than 24 characters!';
  36.     if ( strlen(trim($_POST['username'])) <= 3 ) $Error[] = 'Please fill in a username with more than 3 characters!';
  37.     if ( strlen(trim($_POST['password'])) == 0 ) $Error[] = 'Please fill in a password!';
  38.     elseif ( strlen(trim($_POST['password2'])) == 0 ) $Error[] = 'Please confirm your password!';
  39.     elseif ( $_POST['password'] != $_POST['password2'] ) $Error[] = 'Passwords do not match';
  40.     if ( $Setting['Require_Email'] === true ) {
  41.         if ( strlen(trim($_POST['email'])) == 0 ) $Error[] = 'Incomplete email address!';
  42.         elseif ( strlen(trim($_POST['suffix'])) == 0 ) $Error[] = 'Incomplete email address!';
  43.         elseif ( strlen(trim($_POST['ext'])) == 0 ) $Error[] = 'Incomplete email address!';
  44.         else $email = $_POST['email'].'@'.$_POST['suffix'].'.'.$_POST['ext'];
  45.     }
  46.     if ( ($Setting['Age_Restriction'] === true) && ($_POST['age'] < $Setting['Permitted_Age']) ) $Error[] = 'You do not meet the minimum age requirements to sign up!';
  47.     if ( $Error ) {
  48.         echo 'The following error(s) need to be fixed before you can continue:<br />';
  49.         echo implode('<br />', $Error);
  50.     } else {
  51.         // make database connection -start
  52.         // make a database connection remove this if you already have one running.
  53.             $ident = @mysql_connect($Setting['MySQL_Host'].':'.$Setting['MySQL_Port'],$Setting['MySQL_User'],$Setting['MySQL_Port']);
  54.                 if ( $ident === false ) $Error[] = 'Could not establish connection with database server';
  55.                 if ( @mysql_select_db($Setting['MySQL_mndb']) === false ) $Error[] = 'Could not establish connection with database';
  56.         // make database connection -end
  57.        
  58.         // check if username exits
  59.         $sql = "SELECT id FROM accounts WHERE username='%s' ";
  60.         $sql = sprintf($sql,protect($_POST['username']));
  61.         $qry = @mysql_query($sql);
  62.         if ( $qry === false ) $Error[] = 'I am sorry but we could not proceed with registering your account due a database issue!';
  63.         elseif ( mysql_num_rows($qry) == 1 ) $Error[] = 'I am sorry but this account name is already been taken!';
  64.         if ( $Setting['Require_Email'] === true ) {
  65.             $sql = "SELECT id FROM accounts WHERE email='%s' ";
  66.             $sql = sprintf($sql,protect($email));
  67.             $qry = @mysql_query($sql);     
  68.             if ( $qry === false ) $Error[] = 'I am sorry but we could not proceed with registering your account due a database issue!';
  69.             elseif ( mysql_num_rows($qry) == 1 ) $Error[] = 'I am sorry but this email address is already been taken!';
  70.         }
  71.         if ( $Error ) {
  72.             echo 'The following database error(s) occourd:<br />';
  73.             echo implode('<br />', $Error);
  74.         } else {
  75.             // Register your account!
  76.             if ( $Setting['Require_Email'] === true ) {
  77.                 $sql = "INSERT INTO accounts (username,password,email) VALUES ('%s','%s','%s')";;
  78.                 $sql = sprintf($sql,protect($_POST['username']),md5($_POST['password']),protect($email));
  79.             } else {
  80.                 $sql = "INSERT INTO accounts (username,password) VALUES ('%s','%s')";;
  81.                 $sql = sprintf($sql,protect($_POST['username']),md5($_POST['password']));              
  82.             }
  83.             $qry = @mysql_query($sql);
  84.             if ( $qry === false ) {
  85.                  echo 'I am sorry but we could not proceed with registering your account due a database issue!';
  86.             } else {
  87.                 echo 'Your account has been successfully registred!';
  88.                 $Submitted = true;
  89.             }
  90.         }
  91.     }
  92. }
  93. if ( $Submitted === false ) {
  94.     function repost($var) {
  95.         if ( $_POST[$var] == NULL ) { return ''; }
  96.         else {
  97.             if ( get_magic_quotes_gpc() == 1 ) return stripslashes($_POST[$var]);
  98.             else return $string;
  99.         }
  100.     }
  101. ?>
  102. <form action="" method="post">
  103.     <table width="100%" border="0" cellspacing="5" cellpadding="2">
  104.   <tr>
  105.     <th width="100" scope="row">Username:</th>
  106.     <td><input name="username" type="text" id="username" value="<?php echo repost('username'); ?>" /></td>
  107.   </tr>
  108.   <tr>
  109.     <th scope="row">Password:</th>
  110.     <td><input name="password" type="password" id="password" value="<?php echo repost('password'); ?>" /></td>
  111.   </tr>
  112.   <tr>
  113.     <th scope="row">Password (again): </th>
  114.     <td><input name="password2" type="password" id="password2" value="<?php echo repost('password2'); ?>" /></td>
  115.   </tr>
  116.   <?php
  117.   if ( $Setting['Require_Email'] === true ) {
  118.   ?>
  119.   <tr>
  120.     <th scope="row">Email:</th>
  121.     <td><input name="email" type="text" id="email" value="<?php echo repost('email'); ?>" />
  122.       <strong>@</strong>
  123.       <input name="suffix" type="text" id="suffix" size="10" value="<?php echo repost('suffix'); ?>" />
  124.       <strong>.</strong>
  125.       <input name="ext" type="text" id="ext" size="5" value="<?php echo repost('ext'); ?>" /></td>
  126.   </tr>
  127.   <?php
  128.   }
  129.   if ( $Setting['Age_Restriction'] === true ) {
  130.   ?>
  131.   <tr>
  132.     <th scope="row">Age:</th>
  133.     <td><input name="age"type="text" id="age" size="5" value="<?php echo repost('age'); ?>" /></td>
  134.   </tr>
  135.   <?php
  136.   }
  137.   ?>
  138.   <tr>
  139.     <th scope="row">&nbsp;</th>
  140.     <td><input type="submit" name="Submit" value="Submit" /></td>
  141.   </tr>
  142. </table>
  143. </form>
  144. <?php
  145. }
  146. ?>
  147. </body>
  148. </html>
  149.  
Attachments
registration_script.txt
(6.28 KiB) Downloaded 605 times
Rifke
Pero pero
Pero pero
 
Posts: 719
Joined: Thu Aug 09, 2007 3:01 pm
Location: Belgium

Re: [REQ] Basic Register Script

Postby karl19 on Thu Apr 12, 2012 8:06 am

got this problem even i set the database setting correctly

The following database error(s) occourd:
Could not establish connection with database server
karl19
Little soul
Little soul
 
Posts: 9
Joined: Sat Mar 31, 2012 1:03 pm


Return to PHP / Web Guides, Scripts and tools.

Who is online

Users browsing this forum: No registered users and 8 guests

cron