Bitcoin Forum
April 25, 2024, 01:41:34 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1] 2 »  All
  Print  
Author Topic: PHP address validator (non JSON-RPC)  (Read 4597 times)
Alex Beckenham (OP)
Full Member
***
Offline Offline

Activity: 154
Merit: 100


View Profile
June 14, 2011, 07:36:07 AM
 #1

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

1714052494
Hero Member
*
Offline Offline

Posts: 1714052494

View Profile Personal Message (Offline)

Ignore
1714052494
Reply with quote  #2

1714052494
Report to moderator
1714052494
Hero Member
*
Offline Offline

Posts: 1714052494

View Profile Personal Message (Offline)

Ignore
1714052494
Reply with quote  #2

1714052494
Report to moderator
The trust scores you see are subjective; they will change depending on who you have in your trust list.
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1714052494
Hero Member
*
Offline Offline

Posts: 1714052494

View Profile Personal Message (Offline)

Ignore
1714052494
Reply with quote  #2

1714052494
Report to moderator
theymos
Administrator
Legendary
*
Offline Offline

Activity: 5180
Merit: 12884


View Profile
June 14, 2011, 01:29:43 PM
 #2

I published this a long time ago, but few people seem to use it:
http://pastebin.com/vmRQC7ha

1NXYoJ5xU91Jp83XfVMHwwTUyZFK64BoAD
Alex Beckenham (OP)
Full Member
***
Offline Offline

Activity: 154
Merit: 100


View Profile
June 14, 2011, 01:44:38 PM
 #3

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.

theymos
Administrator
Legendary
*
Offline Offline

Activity: 5180
Merit: 12884


View Profile
June 14, 2011, 04:48:57 PM
 #4

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)
Full Member
***
Offline Offline

Activity: 154
Merit: 100


View Profile
June 15, 2011, 04:13:24 AM
 #5

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 Offline

Activity: 5180
Merit: 12884


View Profile
June 15, 2011, 04:40:01 AM
 #6

Thanks!

1NXYoJ5xU91Jp83XfVMHwwTUyZFK64BoAD
crazy_rabbit
Legendary
*
Offline Offline

Activity: 1204
Merit: 1001


RUM AND CARROTS: A PIRATE LIFE FOR ME


View Profile
August 14, 2012, 07:28:57 AM
 #7

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 Offline

Activity: 5180
Merit: 12884


View Profile
August 15, 2012, 12:04:19 AM
 #8

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]
Hero Member
*****
Offline Offline

Activity: 742
Merit: 500



View Profile WWW
August 15, 2012, 03:10:02 AM
 #9

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 ?

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 Offline

Activity: 5180
Merit: 12884


View Profile
August 15, 2012, 03:26:03 AM
 #10

Will it validate 17FSKMPAyXGR7EQziCqbVfwleGumRosQoh as correct or not ?

It says that that address is invalid, which seems correct.

1NXYoJ5xU91Jp83XfVMHwwTUyZFK64BoAD
[Tycho]
Hero Member
*****
Offline Offline

Activity: 742
Merit: 500



View Profile WWW
August 15, 2012, 04:47:48 AM
 #11

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 Offline

Activity: 5180
Merit: 12884


View Profile
August 15, 2012, 06:12:48 AM
 #12

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 Offline

Activity: 47
Merit: 0



View Profile WWW
November 28, 2012, 09:29:30 AM
 #13

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 :-)
bitcoinget
Hero Member
*****
Offline Offline

Activity: 608
Merit: 502



View Profile WWW
March 19, 2013, 04:34:41 PM
 #14

I found a couple more false positives with the validation code:

1Sq2Pb5pCfPBKZ3U4SFjHMlhvAbz8Vpjk
1C8UDzgYqlhFqduhYzuAjlMQZWBvYahvD1

Is there an updated version of the code somewhere? Thanks.

Earn Bitcoin by Completing Tasks: http://www.bitcoinget.com
Earn Bitcoin Cashback at 300+ Stores: http://www.coinrebates.com
SgtSpike
Legendary
*
Offline Offline

Activity: 1400
Merit: 1005



View Profile
March 19, 2013, 04:44:51 PM
 #15

Oooh, going to integrate this into one of my scripts as well.
canadiannomad
Newbie
*
Offline Offline

Activity: 8
Merit: 0


View Profile
December 25, 2013, 12:52:30 PM
 #16

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
Hero Member
*****
Offline Offline

Activity: 525
Merit: 529


View Profile
December 25, 2013, 01:51:56 PM
 #17

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

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
Seal
Donator
Hero Member
*
Offline Offline

Activity: 848
Merit: 1078


View Profile WWW
March 03, 2014, 05:41:52 PM
 #18

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??

DefiDive - Filter the noise
A clean crypto asset management terminal
theymos
Administrator
Legendary
*
Offline Offline

Activity: 5180
Merit: 12884


View Profile
March 03, 2014, 09:17:57 PM
 #19

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.

1NXYoJ5xU91Jp83XfVMHwwTUyZFK64BoAD
Zickafa
Member
**
Offline Offline

Activity: 112
Merit: 12


View Profile WWW
March 04, 2014, 09:02:32 AM
 #20

What is the advantage in validator for PHP that works without a connection to bitcoind?
Pages: [1] 2 »  All
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!