In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
How to realize the blockchain in PHP? aiming at this problem, this article introduces the corresponding analysis and solution in detail, hoping to help more partners who want to solve this problem to find a more simple and feasible method.
Introduction
What is a blockchain? The official explanation is that blockchain is a distributed accounting system that uses cryptography to concatenate and protect serial transactions (also known as blocks) of its contents. Each block contains the encrypted hash of the previous block, the corresponding timestamp and transaction data (usually represented by the hash value calculated by the Merkel tree algorithm). This design makes the block content difficult to tamper with. A distributed account book concatenated with a block chain allows both parties to record transactions efficiently, and the transaction can be checked permanently.
block
You should have played the idiom to pick up the dragon, and the rule is this: I first say an idiom "a sea of people". The next player needs to use the last word of my idiom as the beginning of the next idiom. that is to say, you need to use the word "sea" as the beginning of the new idiom.
The form of the block chain is a bit like the idiom dragon, that is, the next block must use the hash value of the previous block as the credential to generate the next block. As shown below:
The advantage of this is that starting from any block, you can continuously trace the entire block chain through the hash value of the previous block to the creation block (that is, the first block of the block chain). If there is a malicious attack, the data of the entire blockchain must also be changed. However, calculating the hash value is a time-consuming operation, so it is impossible to change the data of the whole block chain, which ensures the security of the block chain.
Let's use the PHP code to define the chunk:
Class Block {public $prevHash; public $hash; public $timeSt public $data;}
PrevHash: the hash value of the previous block
Hash: the hash value of the current block
TimeStamp: timestamp of chunk generation
Data: data saved by a block
The fields prevHash, hash, and timeStamp are called blockheads in the blockchain, and the hash value of the chunk is calculated using the SHA-256 algorithm. The calculation method is as follows:
Hash = hash ('sha256', $data);}}
First we use the serialize () function to serialize the entire chunk, then use the hash () function to calculate the hash value of the chunk and assign it to the hash field.
The constructor of the block object is as follows: prevHash = $prevHash; $this- > timeStamp = time (); $this- > data = $data; $this- > setBlockHash ();}}
In addition, we provide a method to get the block hash value:
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.