Advertisement
Guest User

Untitled

a guest
Jun 10th, 2016
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.95 KB | None | 0 0
  1. <?php
  2. session_start();
  3. // If user is logged in, header them away
  4. if(isset($_SESSION["username"])){
  5. header("location: message.php?msg=NO to that weenis");
  6. exit();
  7. }
  8. ?><?php
  9. // Ajax calls this NAME CHECK code to execute
  10. if(isset($_POST["usernamecheck"])){
  11. include_once("php_includes/db_conx.php");
  12. $username = preg_replace('#[^a-z0-9]#i', '', $_POST['usernamecheck']);
  13. $sql = "SELECT id FROM users WHERE username='$username' LIMIT 1";
  14. $query = mysqli_query($db_conx, $sql);
  15. $uname_check = mysqli_num_rows($query);
  16. if (strlen($username) < 3 || strlen($username) > 16) {
  17. echo '<strong style="color:#F00;">3 - 16 characters please</strong>';
  18. exit();
  19. }
  20. if (is_numeric($username[0])) {
  21. echo '<strong style="color:#F00;">Usernames must begin with a letter</strong>';
  22. exit();
  23. }
  24. if ($uname_check < 1) {
  25. echo '<strong style="color:#009900;">' . $username . ' is OK</strong>';
  26. exit();
  27. } else {
  28. echo '<strong style="color:#F00;">' . $username . ' is taken</strong>';
  29. exit();
  30. }
  31. }
  32. ?><?php
  33. // Ajax calls this REGISTRATION code to execute
  34. if(isset($_POST["u"])){
  35. // CONNECT TO THE DATABASE
  36. include_once("php_includes/db_conx.php");
  37. // GATHER THE POSTED DATA INTO LOCAL VARIABLES
  38. $u = preg_replace('#[^a-z0-9]#i', '', $_POST['u']);
  39. $e = mysqli_real_escape_string($db_conx, $_POST['e']);
  40. $p = $_POST['p'];
  41. $g = preg_replace('#[^a-z]#', '', $_POST['g']);
  42. $c = preg_replace('#[^a-z ]#i', '', $_POST['c']);
  43. // GET USER IP ADDRESS
  44. $ip = preg_replace('#[^0-9.]#', '', getenv('REMOTE_ADDR'));
  45. // DUPLICATE DATA CHECKS FOR USERNAME AND EMAIL
  46. $sql = "SELECT id FROM users WHERE username='$u' LIMIT 1";
  47. $query = mysqli_query($db_conx, $sql);
  48. $u_check = mysqli_num_rows($query);
  49. // -------------------------------------------
  50. $sql = "SELECT id FROM users WHERE email='$e' LIMIT 1";
  51. $query = mysqli_query($db_conx, $sql);
  52. $e_check = mysqli_num_rows($query);
  53.  
  54. $.ajax({
  55. data: position,
  56. url: 'BACKEND_URL.php',
  57. type: 'post'
  58. });
  59. }
  60.  
  61. //End
  62.  
  63. // FORM DATA ERROR HANDLING
  64. if($u == "" || $e == "" || $p == "" || $g == "" || $c == ""){
  65. echo "The form submission is missing values.";
  66. exit();
  67. } else if ($u_check > 0){
  68. echo "The username you entered is alreay taken";
  69. exit();
  70. } else if ($e_check > 0){
  71. echo "That email address is already in use in the system";
  72. exit();
  73. } else if (strlen($u) < 3 || strlen($u) > 16) {
  74. echo "Username must be between 3 and 16 characters";
  75. exit();
  76. } else if (is_numeric($u[0])) {
  77. echo 'Username cannot begin with a number';
  78. exit();
  79. } else {
  80. // END FORM DATA ERROR HANDLING
  81. // Begin Insertion of data into the database
  82. // Hash the password and apply your own mysterious unique salt
  83. $p_hash = md5($p);
  84. // Add user info into the database table for the main site table
  85. $sql = "INSERT INTO users (username, email, password, gender, country, ip, signup, lat, lng, lastlogin, notescheck)
  86. VALUES('$u','$e','$p_hash','$g','$c','$ip',now(),now(),now())";
  87. $query = mysqli_query($db_conx, $sql);
  88. $uid = mysqli_insert_id($db_conx);
  89. // Establish their row in the useroptions table
  90. $sql = "INSERT INTO useroptions (id, username, background) VALUES ('$uid','$u','original')";
  91. $query = mysqli_query($db_conx, $sql);
  92. // Create directory(folder) to hold each user's files(pics, MP3s, etc.)
  93. if (!file_exists("user/$u")) {
  94. mkdir("user/$u", 0755);
  95. }
  96. // Email the user their activation link
  97. $to = "$e";
  98. $from = "auto_responder@yoursitename.com";
  99. $subject = 'yoursitename Account Activation';
  100. $message = '<!DOCTYPE html><html><head><meta charset="UTF-8"><title>yoursitename Message</title></head><body style="margin:0px; font-family:Tahoma, Geneva, sans-serif;"><div style="padding:10px; background:#333; font-size:24px; color:#CCC;"><a href="http://www.yoursitename.com"><img src="http://www.yoursitename.com/images/logo.png" width="36" height="30" alt="yoursitename" style="border:none; float:left;"></a>yoursitename Account Activation</div><div style="padding:24px; font-size:17px;">Hello '.$u.',<br /><br />Click the link below to activate your account when ready:<br /><br /><a href="http://www.yoursitename.com/activation.php?id='.$uid.'&u='.$u.'&e='.$e.'&p='.$p_hash.'">Click here to activate your account now</a><br /><br />Login after successful activation using your:<br />* E-mail Address: <b>'.$e.'</b></div></body></html>';
  101. $headers = "From: $fromn";
  102. $headers .= "MIME-Version: 1.0n";
  103. $headers .= "Content-type: text/html; charset=iso-8859-1n";
  104. mail($to, $subject, $message, $headers);
  105. echo "signup_success";
  106. exit();
  107. }
  108. exit();
  109. }
  110. ?>
  111. <!DOCTYPE html>
  112. <html>
  113. <head>
  114. <meta charset="UTF-8">
  115. <title>Sign Up</title>
  116. <link rel="icon" href="favicon.ico" type="image/x-icon">
  117. <link href='stylestyle_main.css' rel='stylesheet' type='text/css'>
  118. <link href='stylepageTop_style.css' rel='stylesheet' type='text/css'>
  119. <style type="text/css">
  120. #signupform{
  121. margin-top:24px;
  122. }
  123. #signupform > div {
  124. margin-top: 12px;
  125. }
  126. #signupform > input,select {
  127. width: 200px;
  128. padding: 3px;
  129. background: #F3F9DD;
  130. }
  131. #signupbtn {
  132. font-size:18px;
  133. padding: 12px;
  134. }
  135. #terms {
  136. border:#CCC 1px solid;
  137. background: #F5F5F5;
  138. padding: 12px;
  139. }
  140. </style>
  141. <script src="js/main.js"></script>
  142. <script src="js/ajax.js"></script>
  143. <script>
  144. function restrict(elem){
  145. var tf = _(elem);
  146. var rx = new RegExp;
  147. if(elem == "email"){
  148. rx = /[' "]/gi;
  149. } else if(elem == "username"){
  150. rx = /[^a-z0-9]/gi;
  151. }
  152. tf.value = tf.value.replace(rx, "");
  153. }
  154. function emptyElement(x){
  155. _(x).innerHTML = "";
  156. }
  157. function checkusername(){
  158. var u = _("username").value;
  159. if(u != ""){
  160. _("unamestatus").innerHTML = 'checking ...';
  161. var ajax = ajaxObj("POST", "signup.php");
  162. ajax.onreadystatechange = function() {
  163. if(ajaxReturn(ajax) == true) {
  164. _("unamestatus").innerHTML = ajax.responseText;
  165. }
  166. }
  167. ajax.send("usernamecheck="+u);
  168. }
  169. }
  170. function signup(){
  171. var u = _("username").value;
  172. var e = _("email").value;
  173. var p1 = _("pass1").value;
  174. var p2 = _("pass2").value;
  175. var c = _("country").value;
  176. var g = _("gender").value;
  177. var status = _("status");
  178. if(u == "" || e == "" || p1 == "" || p2 == "" || c == "" || g == ""){
  179. status.innerHTML = "Fill out all of the form data";
  180. } else if(p1 != p2){
  181. status.innerHTML = "Your password fields do not match";
  182. } else if( _("terms").style.display == "none"){
  183. status.innerHTML = "Please view the terms of use";
  184. } else {
  185. _("signupbtn").style.display = "none";
  186. status.innerHTML = 'please wait ...';
  187. var ajax = ajaxObj("POST", "signup.php");
  188. ajax.onreadystatechange = function() {
  189. if(ajaxReturn(ajax) == true) {
  190. if(ajax.responseText != "signup_success"){
  191. status.innerHTML = ajax.responseText;
  192. _("signupbtn").style.display = "block";
  193. } else {
  194. window.scrollTo(0,0);
  195. _("signupform").innerHTML = "OK "+u+", check your email inbox and junk mail box at <u>"+e+"</u> in a moment to complete the sign up process by activating your account. You will not be able to do anything on the site until you successfully activate your account.";
  196. }
  197. }
  198. }
  199. ajax.send("u="+u+"&e="+e+"&p="+p1+"&c="+c+"&g="+g);
  200. }
  201. }
  202. function openTerms(){
  203. _("terms").style.display = "block";
  204. emptyElement("status");
  205. }
  206. /* function addEvents(){
  207. _("elemID").addEventListener("click", func, false);
  208. }
  209. window.onload = addEvents; */
  210. </script>
  211. </head>
  212. <body>
  213. <?php include_once("template_pageTop.php"); ?>
  214. <div id="pageMiddle">
  215. <h3>Sign Up Here</h3>
  216. <form name="signupform" id="signupform" onsubmit="return false;">
  217. <div>Username: </div>
  218. <input id="username" type="text" onblur="checkusername()" onkeyup="restrict('username')" maxlength="16">
  219. <span id="unamestatus"></span>
  220. <div>Email Address:</div>
  221. <input id="email" type="text" onfocus="emptyElement('status')" onkeyup="restrict('email')" maxlength="88">
  222. <div>Create Password:</div>
  223. <input id="pass1" type="password" onfocus="emptyElement('status')" maxlength="100">
  224. <div>Confirm Password:</div>
  225. <input id="pass2" type="password" onfocus="emptyElement('status')" maxlength="100">
  226. <div>Gender:</div>
  227. <select id="gender" onfocus="emptyElement('status')">
  228. <option value=""></option>
  229. <option value="m">Male</option>
  230. <option value="f">Female</option>
  231. </select>
  232. <div>Country:</div>
  233. <select id="country" onfocus="emptyElement('status')">
  234. <?php include_once("template_country_list.php"); ?>
  235. </select>
  236. <div>
  237. <a href="#" onclick="return false" onmousedown="openTerms()">
  238. View the Terms Of Use
  239. </a>
  240. </div>
  241. <div id="terms" style="display:none;">
  242. <h3>Site Terms Of Use</h3>
  243. <p>1. Play nice here.</p>
  244. <p>2. Take a bath before you visit.</p>
  245. <p>3. Brush your teeth before bed.</p>
  246. </div>
  247. <br /><br />
  248. <button id="signupbtn" onclick="signup()">Create Account</button>
  249. <span id="status"></span>
  250. </form>
  251. </div>
  252.  
  253. </body>
  254. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement