Bitcoin Forum

Bitcoin => Development & Technical Discussion => Topic started by: Alex Beckenham on June 14, 2011, 07:36:07 AM



Title: PHP address validator (non JSON-RPC)
Post by: Alex Beckenham on 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


Title: Re: PHP address validator (non JSON-RPC)
Post by: theymos on 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


Title: Re: PHP address validator (non JSON-RPC)
Post by: Alex Beckenham on June 14, 2011, 01:44:38 PM
I published this a long time ago, but few people seem to use it:
http://pastebin.com/vmRQC7ha

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.


Title: Re: PHP address validator (non JSON-RPC)
Post by: theymos on 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.


Title: Re: PHP address validator (non JSON-RPC)
Post by: Alex Beckenham on 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.


Title: Re: PHP address validator (non JSON-RPC)
Post by: theymos on June 15, 2011, 04:40:01 AM
Thanks!


Title: Re: PHP address validator (non JSON-RPC)
Post by: crazy_rabbit on 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,


Title: Re: PHP address validator (non JSON-RPC)
Post by: theymos on 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.


Title: Re: PHP address validator (non JSON-RPC)
Post by: [Tycho] on August 15, 2012, 03:10:02 AM
I published this a long time ago, but few people seem to use it:
http://pastebin.com/vmRQC7ha
Will it validate 17FSKMPAyXGR7EQziCqbVfwleGumRosQoh as correct or not ?


Title: Re: PHP address validator (non JSON-RPC)
Post by: theymos on 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.


Title: Re: PHP address validator (non JSON-RPC)
Post by: [Tycho] on 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 :)


Title: Re: PHP address validator (non JSON-RPC)
Post by: theymos on 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.


Title: Re: PHP address validator (non JSON-RPC)
Post by: matmar10 on November 28, 2012, 09:29:30 AM
I published this a long time ago, but few people seem to use it:
http://pastebin.com/vmRQC7ha

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 :-)


Title: Re: PHP address validator (non JSON-RPC)
Post by: bitcoinget on 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.


Title: Re: PHP address validator (non JSON-RPC)
Post by: SgtSpike on March 19, 2013, 04:44:51 PM
Oooh, going to integrate this into one of my scripts as well.


Title: Re: PHP address validator (non JSON-RPC)
Post by: canadiannomad on 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 (http://pastebin.com/nvmQJBAm)


Title: Re: PHP address validator (non JSON-RPC)
Post by: elbandi on 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/nvmQJBAm (http://pastebin.com/nvmQJBAm)

maybe a generic address tester, like this:

Code:
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


Title: Re: PHP address validator (non JSON-RPC)
Post by: Seal on 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??


Title: Re: PHP address validator (non JSON-RPC)
Post by: theymos on March 03, 2014, 09:17:57 PM
If you're using my checkAddress, do this:

Code:
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.


Title: Re: PHP address validator (non JSON-RPC)
Post by: Zickafa on March 04, 2014, 09:02:32 AM
What is the advantage in validator for PHP that works without a connection to bitcoind?


Title: Re: PHP address validator (non JSON-RPC)
Post by: Parliament on March 04, 2014, 09:22:12 AM
What is the advantage in validator for PHP that works without a connection to bitcoind?
You don't have to install bitcoind.