Advertisement
Guest User

Untitled

a guest
Sep 9th, 2018
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.72 KB | None | 0 0
  1. <!-- how to make members when login "keep me signed in" and how to make users 13+ with the date input -->
  2.  
  3. <?php
  4. if(!empty($_POST["register-user"])) {
  5. /* Form Required Field Validation */
  6. foreach($_POST as $key=>$value) {
  7. if(empty($_POST[$key])) {
  8. $error_message = "All Fields are required";
  9. break;
  10. }
  11. }
  12. /* Password Matching Validation */
  13. if($_POST['password'] != $_POST['confirm_password']){
  14. $error_message = 'Passwords should be same<br>';
  15. }
  16.  
  17. /* Email Validation */
  18. if(!isset($error_message)) {
  19. if (!filter_var($_POST["userEmail"], FILTER_VALIDATE_EMAIL)) {
  20. $error_message = "Invalid Email Address";
  21. }
  22. }
  23. $userName = "userName";
  24.  
  25.  
  26. $usernamelenght = strlen($userName);
  27. if($usernamelenght <= 25)
  28. {}
  29. else
  30. {
  31. $error_message = "Your username cannot exceed 25 characters";
  32.  
  33. }
  34. $email = "email";
  35.  
  36. $emaillenght = strlen($email);
  37. if($emaillenght <= 50)
  38. {}
  39. else
  40. {
  41. $error_message = "Your email cannot exceed 50 characters";
  42.  
  43. }
  44.  
  45. /* Validation to check if gender is selected */
  46. if(!isset($error_message)) {
  47. if(!isset($_POST["gender"])) {
  48. $error_message = " All Fields are required";
  49. }
  50. }
  51.  
  52. /* Validation to check if Terms and Conditions are accepted */
  53. if(!isset($error_message)) {
  54. if(!isset($_POST["terms"])) {
  55. $error_message = "Accept Terms and Conditions to Register";
  56. }
  57. }
  58.  
  59.  
  60.  
  61.  
  62.  
  63. if(!isset($error_message)) {
  64. require_once("dbcontroller.php");
  65. $db_handle = new DBController();
  66. $query = "INSERT INTO members (username, firstname, lastname, password, email, gender, dob) VALUES
  67. ('" . $_POST["userName"] . "', '" . $_POST["firstName"] . "', '" . $_POST["lastName"] . "', '" . md5($_POST["password"]) . "', '" . $_POST["userEmail"] . "', '" . $_POST["gender"] . "' , '" . $_POST["dob"] . "' )";
  68. $result = $db_handle->insertQuery($query);
  69. if(!empty($result)) {
  70. $error_message = "";
  71. $success_message = "You have registered successfully!";
  72. unset($_POST);
  73. } else {
  74. $error_message = "Problem in registration. Try Again!";
  75. }
  76. }
  77.  
  78.  
  79.  
  80. }
  81. ?>
  82. <html>
  83.  
  84. <?php
  85.  
  86.  
  87. include 'C:wamp64wwwEtegostylesignup.css';
  88.  
  89.  
  90. ?>
  91.  
  92. <script type="text/javascript">
  93.  
  94. var minAge = 13;
  95. function _calcAge() {
  96. var dob = new Dob(document.getElementById("dob").value);
  97. var today = new dob();
  98.  
  99. var timeDiff = Math.abs(today.getTime() - dob.getTime());
  100. var age1 = Math.ceil(timeDiff / (1000 * 3600 * 24)) / 365;
  101. return age1;
  102. }
  103. //Compares calculated age with minimum age and acts according to rules//
  104. function _setAge() {
  105.  
  106. var age = _calcAge();
  107. //alert("my age is " + age);
  108. if (age < minAge) {
  109. var jsdemo = "$error_message = "You must be 13 and over";
  110. } else
  111.  
  112. var jsdemo = "$error_message = "correct";
  113.  
  114. }
  115.  
  116.  
  117. </script>
  118.  
  119.  
  120. <head>
  121. <script src='https://www.google.com/recaptcha/api.js'></script>
  122. <title>https://Etego/signup.com</title>
  123. </head>
  124. <body class="bg">
  125.  
  126.  
  127. <form name="frmRegistration" method="post" action="">
  128. <table border="0" width="500" align="center" class="demo-table">
  129. <?php if(!empty($success_message)) { ?>
  130. <div class="success-message"><?php if(isset($success_message)) echo $success_message; ?></div>
  131. <?php } ?>
  132. <?php if(!empty($error_message)) { ?>
  133. <div class="error-message"><?php if(isset($error_message)) echo $error_message; ?></div>
  134. <?php } ?>
  135. <tr>
  136. <td>User Name</td>
  137. <td><input type="text" class="demoInputBox allinsc" name="userName" value="<?php if(isset($_POST['userName'])) echo $_POST['userName']; ?>"></td>
  138. </tr>
  139. <tr>
  140. <td>First Name</td>
  141. <td><input type="text" class="demoInputBox allinsc" name="firstName" value="<?php if(isset($_POST['firstName'])) echo $_POST['firstName']; ?>"></td>
  142. </tr>
  143. <tr>
  144. <td>Last Name</td>
  145. <td><input type="text" class="demoInputBox allinsc" name="lastName" value="<?php if(isset($_POST['lastName'])) echo $_POST['lastName']; ?>"></td>
  146. </tr>
  147. <tr>
  148. <td>Password</td>
  149. <td><input type="password" class="demoInputBox allinsc" name="password" value=""></td>
  150. </tr>
  151. <tr>
  152. <td>Confirm Password</td>
  153. <td><input type="password" class="demoInputBox allinsc" name="confirm_password" value=""></td>
  154. </tr>
  155. <tr>
  156. <td>Email</td>
  157. <td><input type="text" class="demoInputBox allinsc" name="userEmail" value="<?php if(isset($_POST['userEmail'])) echo $_POST['userEmail']; ?>"></td>
  158. </tr>
  159. <tr>
  160. <td>Date Of birth</td>
  161. <td><input type="date" id="dob" value="<?php print(date("YYYY-MM-DD"))?>" class="demoInputBox" name="dob" value="<?php if(isset($_POST['dob'])) echo $_POST['dob']; ?>"></td>
  162. </tr>
  163. <tr>
  164. <td>Gender</td>
  165. <td><input type="radio" name="gender" value="Male" <?php if(isset($_POST['gender']) && $_POST['gender']=="Male") { ?>checked<?php } ?>> Male
  166. <input type="radio" name="gender" value="Female" <?php if(isset($_POST['gender']) && $_POST['gender']=="Female") { ?>checked<?php } ?>> Female
  167. <input type="radio" name="gender" value="not specified" <?php if(isset($_POST['gender']) && $_POST['gender']=="not specified") { ?>checked<?php } ?>> not specified
  168. </td>
  169. </tr>
  170. <tr>
  171. <td colspan=2>
  172. <input type="checkbox" name="terms"> I accept <a href="terms.html">Terms and Conditions</a>
  173. <input type="submit" name="register-user" value="Register" class="btnregister"></td>
  174. </tr>
  175.  
  176. </table>
  177. </form>
  178.  
  179. <div class="bg9"></div>
  180. <div class="header1"></div>
  181. <div class="hdetail1"></div>
  182.  
  183. <div class="header2"></div>
  184. <div class="hdetail2"></div>
  185.  
  186. <a href="index2.php">
  187. <ul>
  188. <li class="etegotxt1">
  189. <span>Etego</span>
  190. </li>
  191. </ul>
  192.  
  193. <img src="EtegoLogo2.png" alt="Etego logo" width="50" height="50" class="logo1">
  194. </a>
  195.  
  196.  
  197. <ul class="ul1">
  198. <li class="li1"><a class="a1 h1" href="index2.php">Home</a></li>
  199. <li class="li1"><a class="a1 n1" href="news.html">News</a></li>
  200. <li class="li1"><a class="a1 c1" href="contact.html">Contact</a></li>
  201. <li class="li1"><a class="a1 aa1" href="about.html">About</a></li>
  202. </ul>
  203.  
  204.  
  205.  
  206.  
  207. <table class="login1">
  208. <tr>
  209. </tr>
  210. <tr >
  211. <td><input type="text" class="inputtext" placeholder="Email or Username">
  212. </td>
  213. <td><input type="password" class="inputtext" placeholder="Password">
  214. </td>
  215. <td>
  216. <div id="button" class="log1">Log In</div>
  217. </td>
  218. </tr>
  219. <tr>
  220. <td>
  221. <div class="row2" class="rowh"><input type="checkbox" checked>Keep me logged in</div>
  222. </td>
  223. <td class="row2 h"><a class="fyp1" href="Contact.html">Forgot your password?</a></td>
  224. </table>
  225.  
  226.  
  227.  
  228.  
  229.  
  230.  
  231.  
  232. <section>
  233. <img src="EtegoLogo2.png" alt="Etego logo" width="200" height="200" class="logo2">
  234.  
  235.  
  236. <h1 class="text2"
  237. data-sitekey="6LdoU28UAAAAALkl4SMrM91_mJRWAXEtb5YYlYof"
  238. data-callback="YourOnSubmitFn" onclick="_setAge()">
  239. Sign Up
  240. </h1>
  241.  
  242. <h1 class="text1">
  243. What is Etego?
  244. </h1>
  245.  
  246. <p class="p1">
  247. Etego is a free social network made for <br /> people who just wants to spend more <br /> time with friends and family. Etego's only goal is to make you happy. you might be a co-worker trying to make an ad for hiring workers, or you might also be a teen trying to make some money by walking your neighbor hood dogs. But after all, <br /> Etego is there to stay and will always be free.
  248. </p>
  249. </section>
  250. <div class="clear-both"></div>
  251.  
  252.  
  253. <p class="cr1"><a href="terms.html" class="tos2">Terms Of Services</a> • <a href="aboutme.html" class="tos2">About the author</a><br />Copyright © 2018-2019 Charles Chevrier All Rights Reserved <br />By clicking register you accept the <a href="terms.html" class="tos2">terms of services</a> and that you have read the <a href="terms.html"class="tos2">privacy policy</a></p>
  254. <div class="bothead"></div>
  255. <div class="botd"></div>
  256. <div class="table1"></div>
  257. </body></html>
  258.  
  259. <?php
  260. class DBController {
  261. public $host = "localhost";
  262. public $user = "root";
  263. public $password = "";
  264. public $database = "members";
  265. public $conn;
  266.  
  267. function __construct() {
  268. $this->conn = $this->connectDB();
  269. }
  270.  
  271. function connectDB() {
  272. $this->conn = mysqli_connect($this->host,$this->user,$this->password,$this->database);
  273. return $this->conn;
  274. }
  275.  
  276. function runQuery($query) {
  277. $result = mysqli_query($this->conn,$query);
  278. while($row=mysqli_fetch_assoc($result)) {
  279. $resultset[] = $row;
  280. }
  281. if(!empty($resultset))
  282. return $resultset;
  283. }
  284.  
  285. function numRows($query) {
  286. $result = mysqli_query($this->conn,$query);
  287. $rowcount = mysqli_num_rows($result);
  288. return $rowcount;
  289. }
  290.  
  291. function updateQuery($query) {
  292. $result = mysqli_query($this->conn,$query);
  293. if (!$result) {
  294. die('Invalid query1: ' . mysqli_error($this->conn));
  295. } else {
  296. return $result;
  297. }
  298. }
  299.  
  300. function insertQuery($query) {
  301. $result = mysqli_query($this->conn,$query);
  302. if (!$result) {
  303. die('Invalid query2: ' . mysqli_error($this->conn));
  304. } else {
  305. return $result;
  306. }
  307. }
  308.  
  309. function deleteQuery($query) {
  310. $result = mysqli_query($this->conn,$query);
  311. if (!$result) {
  312. die('Invalid query3: ' . mysqli_error($this->conn));
  313. } else {
  314. return $result;
  315. }
  316. }
  317. }
  318.  
  319.  
  320. /* Email already exists */
  321. /*line 63*/
  322. $db = new DBController;
  323. $stmt = $db->conn->prepare("SELECT * FROM members WHERE email = ?");
  324. $stmt->bind_param("s", $email);
  325. $stmt->execute();
  326.  
  327. $result = $stmt->get_result();
  328.  
  329. if($result->num_rows > 0) {
  330. $error_message = "Email already exists";
  331. }
  332.  
  333. //end of email existance
  334. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement