Alex Beckenham (OP)
|
![](https://bitcointalk.org/Themes/custom1/images/post/xx.gif) |
June 14, 2011, 07:36:07 AM |
|
Hi,
I'm wondering if someone has coded a simple bitcoin address validator for PHP that works without a connection to bitcoind.
I thought I had one, but now I can't seem to find it.
Thanks, Alex
|
|
|
|
theymos
Administrator
Legendary
Offline
Activity: 5306
Merit: 13220
|
![](https://bitcointalk.org/Themes/custom1/images/post/xx.gif) |
June 14, 2011, 01:29:43 PM |
|
I published this a long time ago, but few people seem to use it: http://pastebin.com/vmRQC7ha
|
1NXYoJ5xU91Jp83XfVMHwwTUyZFK64BoAD
|
|
|
Alex Beckenham (OP)
|
![](https://bitcointalk.org/Themes/custom1/images/post/xx.gif) |
June 14, 2011, 01:44:38 PM |
|
Thanks, that's just what I was looking for... What are the PHP requirements for this? If I'm using PHP5, do I need to add anything else to the install? Thanks.
|
|
|
|
theymos
Administrator
Legendary
Offline
Activity: 5306
Merit: 13220
|
![](https://bitcointalk.org/Themes/custom1/images/post/xx.gif) |
June 14, 2011, 04:48:57 PM |
|
It requires the bcmath PHP extension, which is usually included by default in binary releases of PHP. Nothing else is required.
|
1NXYoJ5xU91Jp83XfVMHwwTUyZFK64BoAD
|
|
|
Alex Beckenham (OP)
|
![](https://bitcointalk.org/Themes/custom1/images/post/xx.gif) |
June 15, 2011, 04:13:24 AM |
|
It requires the bcmath PHP extension, which is usually included by default in binary releases of PHP. Nothing else is required.
Thanks, I'm sure an early member like you has a few coins already but I just sent you a tip. Very useful bit of code.
|
|
|
|
theymos
Administrator
Legendary
Offline
Activity: 5306
Merit: 13220
|
![](https://bitcointalk.org/Themes/custom1/images/post/xx.gif) |
June 15, 2011, 04:40:01 AM |
|
Thanks!
|
1NXYoJ5xU91Jp83XfVMHwwTUyZFK64BoAD
|
|
|
crazy_rabbit
Legendary
Offline
Activity: 1204
Merit: 1002
RUM AND CARROTS: A PIRATE LIFE FOR ME
|
![](https://bitcointalk.org/Themes/custom1/images/post/xx.gif) |
August 14, 2012, 07:28:57 AM |
|
I just found this script and I find it really useful, so I wanted to say thanks as well!
I had a question, can I use it only for testing the validity of a BTC address or can the functions inside the script be used for other purposes as well?
thanks,
|
more or less retired.
|
|
|
theymos
Administrator
Legendary
Offline
Activity: 5306
Merit: 13220
|
![](https://bitcointalk.org/Themes/custom1/images/post/xx.gif) |
August 15, 2012, 12:04:19 AM |
|
I had a question, can I use it only for testing the validity of a BTC address or can the functions inside the script be used for other purposes as well? You can use it for other things. The base58 functions can be used for working with other address formats, for example.
|
1NXYoJ5xU91Jp83XfVMHwwTUyZFK64BoAD
|
|
|
[Tycho]
|
![](https://bitcointalk.org/Themes/custom1/images/post/xx.gif) |
August 15, 2012, 03:10:02 AM |
|
Will it validate 17FSKMPAyXGR7EQziCqbVfwleGumRosQoh as correct or not ?
|
Welcome to my bitcoin mining pool: https://deepbit.net - Both payment schemes (including PPS), instant payout, no invalid blocks ! ICBIT Trading platform : USD/BTC futures trading, Bitcoin difficulty futures ( NEW!). Third year in bitcoin business.
|
|
|
theymos
Administrator
Legendary
Offline
Activity: 5306
Merit: 13220
|
![](https://bitcointalk.org/Themes/custom1/images/post/xx.gif) |
August 15, 2012, 03:26:03 AM |
|
Will it validate 17FSKMPAyXGR7EQziCqbVfwleGumRosQoh as correct or not ?
It says that that address is invalid, which seems correct.
|
1NXYoJ5xU91Jp83XfVMHwwTUyZFK64BoAD
|
|
|
[Tycho]
|
![](https://bitcointalk.org/Themes/custom1/images/post/xx.gif) |
August 15, 2012, 04:47:48 AM |
|
It says that that address is invalid, which seems correct.
Nice. There was a similar validator showing it as valid :)
|
Welcome to my bitcoin mining pool: https://deepbit.net - Both payment schemes (including PPS), instant payout, no invalid blocks ! ICBIT Trading platform : USD/BTC futures trading, Bitcoin difficulty futures ( NEW!). Third year in bitcoin business.
|
|
|
theymos
Administrator
Legendary
Offline
Activity: 5306
Merit: 13220
|
![](https://bitcointalk.org/Themes/custom1/images/post/xx.gif) |
August 15, 2012, 06:12:48 AM |
|
Oh, checkAddress actually says that that's valid. My web interfaces all check base58 validity before using checkAddress... I'll update it soon to fix this.
|
1NXYoJ5xU91Jp83XfVMHwwTUyZFK64BoAD
|
|
|
matmar10
Newbie
Offline
Activity: 47
Merit: 0
|
![](https://bitcointalk.org/Themes/custom1/images/post/xx.gif) |
November 28, 2012, 09:29:30 AM |
|
Thanks for posting this! It's the best one I've found so far... I've run about 50 public keys through using PhpUnit through so far and it correctly validated them :-)
|
|
|
|
bitcoinget
|
![](https://bitcointalk.org/Themes/custom1/images/post/xx.gif) |
March 19, 2013, 04:34:41 PM |
|
I found a couple more false positives with the validation code:
1Sq2Pb5pCfPBKZ3U4SFjHMlhvAbz8Vpjk 1C8UDzgYqlhFqduhYzuAjlMQZWBvYahvD1
Is there an updated version of the code somewhere? Thanks.
|
|
|
|
SgtSpike
Legendary
Offline
Activity: 1400
Merit: 1005
|
![](https://bitcointalk.org/Themes/custom1/images/post/xx.gif) |
March 19, 2013, 04:44:51 PM |
|
Oooh, going to integrate this into one of my scripts as well.
|
|
|
|
canadiannomad
Newbie
Offline
Activity: 8
Merit: 0
|
![](https://bitcointalk.org/Themes/custom1/images/post/xx.gif) |
December 25, 2013, 12:52:30 PM |
|
Sorry to revive this topic, but I wanted to update it to mention that I took the above script and quickly converted it to a class so we don't contaminate our name spaces so much... Also added the TestNet address version. http://pastebin.com/nvmQJBAm
|
|
|
|
elbandi
|
![](https://bitcointalk.org/Themes/custom1/images/post/xx.gif) |
December 25, 2013, 01:51:56 PM |
|
Sorry to revive this topic, but I wanted to update it to mention that I took the above script and quickly converted it to a class so we don't contaminate our name spaces so much... Also added the TestNet address version. http://pastebin.com/nvmQJBAmmaybe a generic address tester, like this: abstract class CoinValidator { private $addressversion = "00"; //this is a hex byte abstract protected function getAddressVersion($testnet);
public function __construct($testnet = false) { $this->addressversion = $this->getAddressVersion($testnet); } ... }
class BitCoinValidator extends CoinValidator { protected function getAddressVersion($testnet) { return ($testnet) ? "6F" : "00"; //TestNet vs ProductionNet } }
class LiteCoinValidator extends CoinValidator { protected function getAddressVersion($testnet) { return ($testnet) ? "6F" : "30"; //TestNet vs ProductionNet } }
class FooCoinValidator extends CoinValidator { protected function getAddressVersion($testnet) { return ($testnet) ? "XX" : "XX"; //TestNet vs ProductionNet } } ...
Elbandi
|
|
|
|
Seal
Donator
Hero Member
Offline
Activity: 848
Merit: 1078
|
![](https://bitcointalk.org/Themes/custom1/images/post/xx.gif) |
March 03, 2014, 05:41:52 PM |
|
I found a couple more false positives with the validation code:
1Sq2Pb5pCfPBKZ3U4SFjHMlhvAbz8Vpjk 1C8UDzgYqlhFqduhYzuAjlMQZWBvYahvD1
Is there an updated version of the code somewhere? Thanks.
bump. Any take on this? Those addresses seem valid to me??
|
|
|
|
theymos
Administrator
Legendary
Offline
Activity: 5306
Merit: 13220
|
![](https://bitcointalk.org/Themes/custom1/images/post/xx.gif) |
March 03, 2014, 09:17:57 PM |
|
If you're using my checkAddress, do this: if(!preg_match('/^[1-9A-HJ-NP-Za-km-z]{20,40}$/', $address) || !checkAddress($address) ) invalid address My checkAddress assumes that the input is valid base58. The PHP should probably be rewritten to be more efficient.
|
1NXYoJ5xU91Jp83XfVMHwwTUyZFK64BoAD
|
|
|
Zickafa
|
![](https://bitcointalk.org/Themes/custom1/images/post/xx.gif) |
March 04, 2014, 09:02:32 AM |
|
What is the advantage in validator for PHP that works without a connection to bitcoind?
|
|
|
|
|