Advertisement
Guest User

Untitled

a guest
Jul 4th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.49 KB | None | 0 0
  1. <?php
  2. session_start();
  3. include("conf-inc.php");
  4.  
  5. //nak check sama ada username dah digunakan ke belum
  6.  
  7. function usernameTaken($uname){
  8. global $conn;
  9. if(!get_magic_quotes_gpc()){
  10. $uname = addslashes($uname);
  11. }
  12. $sql = "select demo_uname from demouser where demo_uname = '$uname'";
  13. $result = mysql_query($sql,$conn);
  14. return (mysql_numrows($result) > 0);
  15. }
  16.  
  17.  
  18. //Inserts data dalam database arr
  19.  
  20. function insertNewUser($demouser){
  21. global $conn;
  22.  
  23. $fname = mysql_escape_string($demouser['demo_fname']);
  24. $lname = mysql_escape_string($demouser['demo_lname']);
  25. $add1 = mysql_escape_string($demouser['demo_add1']);
  26. $country = mysql_escape_string($demouser['demo_country']);
  27. $kod = mysql_escape_string($demouser['demo_kod']);
  28. $state = mysql_escape_string($demouser['demo_state']);
  29. $email = mysql_escape_string($demouser['demo_email']);
  30. $uname = mysql_escape_string($demouser['demo_uname']);
  31. $password = mysql_escape_string($demouser['demo_password']);
  32. $ip = $_SERVER['REMOTE_ADDR'];
  33.  
  34.  
  35. $sql = "INSERT INTO $db.demouser (demo_fname, demo_lname, demo_add1, demo_country, demo_kod, demo_state, demo_email, demo_uname, demo_password, demo_ip ,demo_acct) VALUES ('$fname','$lname','$add1','$country','$kod','$state','$email','$uname','$password','$ip',20)";
  36. return mysql_query($sql,$conn);
  37. }
  38.  
  39. //fungsi nak display message samaada berjaya or tak
  40.  
  41. function displayStatus(){
  42. $uname = $_SESSION['reguname'];
  43. if($_SESSION['regresult']){
  44. ?>
  45.  
  46. <h1>Registered!</h1>
  47. <p>Thank you <b><? echo $uname; ?></b>, your information has been added to the database, you may now</p>
  48.  
  49. <?
  50. }
  51. else{
  52. ?>
  53.  
  54. <h1>Registration Failed</h1>
  55. <p>We're sorry, but an error has occurred and your registration for the username <b><? echo $uname; ?></b>, could not be completed.<br>
  56. Please try again at a later time.</p>
  57.  
  58. <?
  59. }
  60. unset($_SESSION['reguname']);
  61. unset($_SESSION['registered']);
  62. unset($_SESSION['regresult']);
  63. }
  64.  
  65. if(isset($_SESSION['registered'])){
  66.  
  67. //hanya akan kuar bila percubaan utk register arr
  68.  
  69. ?>
  70.  
  71. <html>
  72. <title>Registration Page</title>
  73. <body>
  74.  
  75. <? displayStatus(); ?>
  76.  
  77. </body>
  78. </html>
  79.  
  80. <?
  81. return;
  82. }
  83.  
  84. /**
  85. * Determines whether or not to show to sign-up form
  86. * based on whether the form has been submitted, if it
  87. * has, check the database for consistency and create
  88. * the new account.
  89. */
  90. if(isset($_POST['f_submit'])){
  91. /* Make sure all fields were entered */
  92. if(!$_POST['uname'] || !$_POST['password']){
  93. die('You didn\'t fill in a required field.');
  94. }
  95.  
  96. /* Spruce up username, check length */
  97. $_POST['uname'] = trim($_POST['uname']);
  98. if(strlen($_POST['uname']) > 30){
  99. die("Sorry, the username is longer than 30 characters, please shorten it.");
  100. }
  101.  
  102. /* Check if username is already in use */
  103. if(usernameTaken($_POST['uname'])){
  104. $use = $_POST['uname'];
  105. die("Sorry, the username: <strong>$use</strong> is already taken, please pick another one.");
  106. }
  107.  
  108. /* Add the new account to the database */
  109. $md5pass = md5($_POST['password']);
  110. $_SESSION['reguname'] = $_POST['uname'];
  111. $_SESSION['regresult'] = insertNewUser($_POST['uname'], $md5pass);
  112. $_SESSION['registered'] = true;
  113. echo "<meta http-equiv=\"Refresh\" content=\"0;url=$HTTP_SERVER_VARS[PHP_SELF]\">";
  114. return;
  115. }
  116.  
  117. /**
  118. * This is the page with the sign-up form, the names
  119. * of the input fields are important and should not
  120. * be changed.
  121. */
  122. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement