Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- I have a small programm where i take in a users Bitcoin address as input and than insert it into mysql database.
- for the input form i have this
- <form class="" action="submit.php" method="post">
- <input type="text" name="address" placeholder="your Bitcoin address">
- <button type="submit" name="submit" class="btn btn-info">Submit</button>
- </form>
- the submit php looks like this
- include_once 'db.php';
- $eth = mysqli_real_escape_string($conn,$_POST['address']);
- $sql = "INSERT INTO address(address) VALUES('$eth');";
- mysqli_query($conn, $sql);
- header("Location: ../bitcoin/transfer.php");
- What i want to do is
- user inputs bitcoin address and clicks submit button
- 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.
- If input isnt valid - display error message
- Im using php for everything
- And the code to validate if bitcoin address is valid is this
- <?php
- function checkAddress($address)
- {
- $origbase58 = $address;
- $dec = "0";
- for ($i = 0; $i < strlen($address); $i++)
- {
- $dec = bcadd(bcmul($dec,"58",0),strpos("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz",substr($address,$i,1)),0);
- }
- $address = "";
- while (bccomp($dec,0) == 1)
- {
- $dv = bcdiv($dec,"16",0);
- $rem = (integer)bcmod($dec,"16");
- $dec = $dv;
- $address = $address.substr("0123456789ABCDEF",$rem,1);
- }
- $address = strrev($address);
- for ($i = 0; $i < strlen($origbase58) && substr($origbase58,$i,1) == "1"; $i++)
- {
- $address = "00".$address;
- }
- if (strlen($address)%2 != 0)
- {
- $address = "0".$address;
- }
- if (strlen($address) != 50)
- {
- return false;
- }
- if (hexdec(substr($address,0,2)) > 0)
- {
- return false;
- }
- return substr(strtoupper(hash("sha256",hash("sha256",pack("H*",substr($address,0,strlen($address)-8)),true))),0,8) == substr($address,strlen($address)-8);
- }
- ?>
- I just dont know how to put this together into a working project
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement