Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [PHP]Zmiana wielkośći liter adresów email..
assasin
post 13.04.2010, 22:10:19
Post #1





Grupa: Zarejestrowani
Postów: 196
Pomógł: 0
Dołączył: 13.11.2008

Ostrzeżenie: (0%)
-----


Po rejestracji wprowadzony email do bazy jest dużymi literami.. co powoduje że na jeden email można się rejestrować 1000 razy.. co trzeba zmienić żeby emaile był wprowadzane do bazy małymi literami?

  1. <?php
  2.  
  3. // Configuration.
  4. // Realm database.
  5. $r_db = "realmd_tbc";
  6. // IP (and port).
  7. $ip = ":3306";
  8. // Username.
  9. $user = "";
  10. // Password.
  11. $pass = "";
  12. // Site title.
  13. $title = "Registration Form";
  14. $title2 = "Some Server";
  15. // End config.
  16.  
  17. $page = '<?xml version="1.0" encoding="utf-8" ?>
  18. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  19. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  20. <head>
  21. <title>' . $title . '</title>
  22. </head>
  23. <body style="background-color:black;color:yellow;font-family:verdana;">
  24. <form method="post" action="' . $_SERVER["SCRIPT_NAME"] . '">
  25. <p style="text-align:center;">
  26. <strong>' . $title2 . ' - ' . $title . '</strong>
  27. <br /><br /><br />
  28. Username:
  29. <br /><input name="username" type="text" maxlength="14" /><br />
  30. Password:
  31. <br /><input name="password" type="password" maxlength="12" /><br />
  32. Email:
  33. <br /><input name="email" type="text" maxlength="50" />
  34. <br /><input name="tbc" type="checkbox" checked="checked" /> TBC<br /><br /><br />
  35. <button type="submit">Submit</button>
  36. </p>
  37. </form>
  38. </body>
  39. </html>';
  40.  
  41. function error_s ($text) {
  42. echo("<p style=\"background-color:black;color:yellow;font-family:verdana;\">" . $text);
  43. echo("<br /><br /><a style=\"color:orange;\" href=\"" . $_SERVER["SCRIPT_NAME"] . "\">Go back...</a></p>");
  44. };
  45.  
  46. $user_chars = "#[^a-zA-Z0-9_\-]#";
  47. $email_chars = "/^[^0-9][A-z0-9_]+([.][A-z0-9_]+)*[@][A-z0-9_]+([.][A-z0-9_]+)*[.][A-z]{2,4}$/";
  48.  
  49. $con = @mysql_connect($ip, $user, $pass);
  50. if (!$con) {
  51. error_s("Unable to connect to database: " . mysql_error());
  52. };
  53.  
  54. if (!empty($_POST)) {
  55. if ((empty($_POST["username"]))||(empty($_POST["password"]))||(empty($_POST["email"]))||(empty($_POST["tbc"])) ) {
  56. error_s("You did not enter all the required information.");
  57. exit();
  58. } else {
  59. $username = strtoupper($_POST["username"]);
  60. $password = strtoupper($_POST["password"]);
  61. $email = strtoupper($_POST["email"]);
  62. if (strlen($username) < 5) {
  63. error_s("Username too short.");
  64. exit();
  65. };
  66. if (strlen($username) > 14) {
  67. error_s("Username too long.");
  68. exit();
  69. };
  70. if (strlen($password) < 8) {
  71. error_s("Password too short.");
  72. exit();
  73. };
  74. if (strlen($password) > 12) {
  75. error_s("Password too long.");
  76. exit();
  77. };
  78. if (strlen($email) < 5) {
  79. error_s("Email was too short.");
  80. exit();
  81. };
  82. if (strlen($email) > 50) {
  83. error_s("Email was too long.");
  84. exit();
  85. };
  86. if (preg_match($user_chars,$username)) {
  87. error_s("Username contained illegal characters.");
  88. exit();
  89. };
  90. if (preg_match($user_chars,$password)) {
  91. error_s("Password contained illegal characters.");
  92. exit();
  93. };
  94. if (!preg_match($email_chars,$email)) {
  95. error_s("Email was in an incorrect format.");
  96. exit();
  97. };
  98. if ($_POST['tbc'] != "on") {
  99. $tbc = "0";
  100. } else {
  101. $tbc = "1";
  102. };
  103. $username = mysql_real_escape_string($username);
  104. $password = mysql_real_escape_string($password);
  105. $email = mysql_real_escape_string($email);
  106. $qry = @mysql_query("select username from " . mysql_real_escape_string($r_db) . ".account where username = '" . $username . "'", $con);
  107. if (!$qry) {
  108. error_s("Error querying database: " . mysql_error());
  109. };
  110. if ($existing_username = mysql_fetch_assoc($qry)) {
  111. foreach ($existing_username as $key => $value) {
  112. $existing_username = $value;
  113. };
  114. };
  115. $existing_username = strtoupper($existing_username);
  116. if ($existing_username == strtoupper($_POST['username'])) {
  117. error_s("That username is already taken.");
  118. exit();
  119. };
  120. unset($qry);
  121. $qry = @mysql_query("select email from " . mysql_real_escape_string($r_db) . ".account where email = '" . $email . "'", $con);
  122. if (!$qry) {
  123. error_s("Error querying database: " . mysql_error());
  124. };
  125. if ($existing_email = mysql_fetch_assoc($qry)) {
  126. foreach ($existing_email as $key => $value) {
  127. $existing_email = $value;
  128. };
  129. };
  130. if ($existing_email == $_POST['email']) {
  131. error_s("That email is already in use.");
  132. exit();
  133. };
  134. unset($qry);
  135. $sha_pass_hash = sha1(strtoupper($username) . ":" . strtoupper($password));
  136. $register_sql = "insert into " . mysql_real_escape_string($r_db) . ".account (username, sha_pass_hash, email, expansion) values (upper('" . $username . "'),'" . $sha_pass_hash . "','" . $email . "','" . $tbc . "')";
  137. $qry = @mysql_query($register_sql, $con);
  138. if (!$qry) {
  139. error_s("Error creating account: " . mysql_error());
  140. };
  141. echo("Account successfully created.");
  142. exit();
  143. };
  144. } else {
  145. echo($page);
  146. };
  147.  
  148. ?>


Ten post edytował assasin 13.04.2010, 22:11:18
Go to the top of the page
+Quote Post
Wicepsik
post 13.04.2010, 22:15:12
Post #2





Grupa: Zarejestrowani
Postów: 1 575
Pomógł: 299
Dołączył: 26.03.2009

Ostrzeżenie: (20%)
X----


Twój kod? Sprawdź w manualu jakie są efekty użycia funkcji strtoupper


--------------------
Go to the top of the page
+Quote Post
blooregard
post 13.04.2010, 22:16:16
Post #3


Newsman


Grupa: Moderatorzy
Postów: 2 033
Pomógł: 290
Dołączył: 21.12.2007
Skąd: Łódź




  1. $register_sql = "insert into " . mysql_real_escape_string($r_db) . ".account (username, sha_pass_hash, email, expansion) values (upper('" . $username . "'),'" . $sha_pass_hash . "','" . $email . "','" . $tbc . "')";


http://pl2.php.net/strtolower
http://dev.mysql.com/doc/refman/5.1/en/str...#function_lower


--------------------
Life's simple... You make choices and don't look back...
Go to the top of the page
+Quote Post
assasin
post 17.04.2010, 13:41:53
Post #4





Grupa: Zarejestrowani
Postów: 196
Pomógł: 0
Dołączył: 13.11.2008

Ostrzeżenie: (0%)
-----


Hmm zmieniłem strtoupper na strtolower no i efekt jest taki że teraz wprowadza małymi literami.. i jeśli zarejestruje się np:
test@os.pl to ponownie mogę zarejestrować się na ten sam email tylko dużymi literami TEST@OS.PL i żaden błąd mi nie wywali.. a więc co mam zrobić?

Jakiś pomysł?
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 13.06.2025 - 04:01