Advertisement
Guest User

Untitled

a guest
Dec 12th, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.96 KB | None | 0 0
  1. <?php
  2.  
  3. // Function for check address
  4. function checkAddress($address) {
  5.  
  6. $origbase58 = $address;
  7. $dec = "0";
  8.  
  9. for ($i = 0; $i < strlen($address); $i++) {
  10. $dec = bcadd(bcmul($dec,"58",0),strpos("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz",substr($address,$i,1)),0);
  11. }
  12.  
  13. $address = "";
  14.  
  15. while (bccomp($dec,0) == 1) {
  16. $dv = bcdiv($dec,"16",0);
  17. $rem = (integer)bcmod($dec,"16");
  18. $dec = $dv;
  19. $address = $address.substr("0123456789ABCDEF",$rem,1);
  20. }
  21.  
  22. $address = strrev($address);
  23.  
  24. for ($i = 0; $i < strlen($origbase58) && substr($origbase58,$i,1) == "1"; $i++) {
  25. $address = "00".$address;
  26. }
  27.  
  28. if (strlen($address)%2 != 0) {
  29. $address = "0".$address;
  30. }
  31.  
  32. if (strlen($address) != 50) {
  33. return false;
  34. }
  35.  
  36. if (hexdec(substr($address,0,2)) > 0) {
  37. return false;
  38. }
  39.  
  40. return substr(strtoupper(hash("sha256",hash("sha256",pack("H*",substr($address,0,strlen($address)-8)),true))),0,8) == substr($address,strlen($address)-8);
  41. }
  42.  
  43. include_once 'db.php';
  44. ?>
  45. <!DOCTYPE html>
  46. <html>
  47. <head>
  48. <title>Save address</title>
  49. </head>
  50. <body>
  51. <?php
  52.  
  53. // Check if form submitted
  54. if($_SERVER['REQUEST_METHOD'] == 'POST') {
  55.  
  56. // Check if address valid and insert into db if so
  57. if(checkAddress($_POST['address'])){
  58.  
  59. // Save address
  60. $request = $conn->prepare('INSERT INTO address VALUES (:address)');
  61. $request->execute([
  62. 'address' => $_POST['address']
  63. ]);
  64.  
  65. // Show success
  66. ?>
  67. <b>Address registered successfully ( You can use HTML here ).</b>
  68. <?php
  69. } else {
  70.  
  71. // Display error if address not valid
  72. ?>
  73. <b>Can't verify address ( You can use HTML here ).</b>
  74. <?php
  75. }
  76. } else {
  77.  
  78. // Display form if form not submitted
  79. ?>
  80. <form method="POST">
  81. <input type="text" placeholder="Address" name="address" id="address" />
  82. <button type="submit">Submit</button>
  83. </form>
  84. <?php
  85. }
  86. ?>
  87. </body>
  88. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement