isValid($addr, $version)
$addr: A bitcoin address $version: The version to test against, defaults to MAINNET Returns a boolean indicating if the address is valid or not.
INSTALL
Download from GitHub or composer require linusu/bitcoin-address-validator
USE
use \LinusU\Bitcoin\AddressValidator;
// This is a valid address and will thus return true.
AddressValidator::isValid('1AGNa15ZQXAZUgFiqJ2i7Z2DPU2J6hW62i');
USING IT IN CODE
<?php
include 'connect.php';
include 'LinusU\Bitcoin\AddressValidator.php';
use \LinusU\Bitcoin\AddressValidator;
if(isset($_POST['address']) & isset($_POST['terms'])){
$address=$_POST['address'];
if(AddressValidator::isValid($address)){
// add
$date=date("Y-m-d");
$request="INSERT INTO bitcoin (address, date) VALUES ('$address','$date')";
mysqli_query($connect, $request) or die ("Error while writing to database! Try again...");
mysqli_close($connect);
}else{
// not valid
throw new Exception('Invalid Bitcoin Address');
}
}
?>