Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // Function for check address
- 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);
- }
- include_once 'db.php';
- ?>
- <!DOCTYPE html>
- <html>
- <head>
- <title>Save address</title>
- </head>
- <body>
- <?php
- // Check if form submitted
- if($_SERVER['REQUEST_METHOD'] == 'POST') {
- // Check if address valid and insert into db if so
- if(checkAddress($_POST['address'])){
- // Save address
- $request = $conn->prepare('INSERT INTO address VALUES (:address)');
- $request->execute([
- 'address' => $_POST['address']
- ]);
- // Show success
- ?>
- <b>Address registered successfully ( You can use HTML here ).</b>
- <?php
- } else {
- // Display error if address not valid
- ?>
- <b>Can't verify address ( You can use HTML here ).</b>
- <?php
- }
- } else {
- // Display form if form not submitted
- ?>
- <form method="POST">
- <input type="text" placeholder="Address" name="address" id="address" />
- <button type="submit">Submit</button>
- </form>
- <?php
- }
- ?>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement