Advertisement
Guest User

Untitled

a guest
Dec 10th, 2019
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.17 KB | None | 0 0
  1. I have a small programm where i take in a users Bitcoin address as input and than insert it into mysql database.
  2.  
  3. for the input form i have this
  4.  
  5. <form class="" action="submit.php" method="post">
  6. <input type="text" name="address" placeholder="your Bitcoin address">
  7. <button type="submit" name="submit" class="btn btn-info">Submit</button>
  8. </form>
  9. the submit php looks like this
  10.  
  11. include_once 'db.php';
  12.  
  13. $eth = mysqli_real_escape_string($conn,$_POST['address']);
  14.  
  15.  
  16. $sql = "INSERT INTO address(address) VALUES('$eth');";
  17. mysqli_query($conn, $sql);
  18.  
  19. header("Location: ../bitcoin/transfer.php");
  20. What i want to do is
  21.  
  22. user inputs bitcoin address and clicks submit button
  23.  
  24. which than validates the bitcoin address and if address is valid- he can click submit button and gets redirected to a different part of my site- and if adress is valid it gets added to mysql database.
  25.  
  26. If input isnt valid - display error message
  27.  
  28. Im using php for everything
  29.  
  30. And the code to validate if bitcoin address is valid is this
  31.  
  32. <?php
  33.  
  34. function checkAddress($address)
  35. {
  36. $origbase58 = $address;
  37. $dec = "0";
  38.  
  39. for ($i = 0; $i < strlen($address); $i++)
  40. {
  41. $dec = bcadd(bcmul($dec,"58",0),strpos("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz",substr($address,$i,1)),0);
  42. }
  43.  
  44. $address = "";
  45.  
  46. while (bccomp($dec,0) == 1)
  47. {
  48. $dv = bcdiv($dec,"16",0);
  49. $rem = (integer)bcmod($dec,"16");
  50. $dec = $dv;
  51. $address = $address.substr("0123456789ABCDEF",$rem,1);
  52. }
  53.  
  54. $address = strrev($address);
  55.  
  56. for ($i = 0; $i < strlen($origbase58) && substr($origbase58,$i,1) == "1"; $i++)
  57. {
  58. $address = "00".$address;
  59. }
  60.  
  61. if (strlen($address)%2 != 0)
  62. {
  63. $address = "0".$address;
  64. }
  65.  
  66. if (strlen($address) != 50)
  67. {
  68. return false;
  69. }
  70.  
  71. if (hexdec(substr($address,0,2)) > 0)
  72. {
  73. return false;
  74. }
  75.  
  76. return substr(strtoupper(hash("sha256",hash("sha256",pack("H*",substr($address,0,strlen($address)-8)),true))),0,8) == substr($address,strlen($address)-8);
  77. }
  78.  
  79. ?>
  80. I just dont know how to put this together into a working project
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement