本文原始地址:php区块链demo
今年区块链特别火,我也很火啊。我火什么呢。前几年,公众平台出现,还得花时间去学去看,后来小程序出现,又得花时间精力去学去看。现在比特币、以太坊等去中心化货币带起了区块链的发展。还得学。
没办法,技术改变师姐。不,是改变世界。
前些天看到python写的50行代码实现的简单区块链。今天让我们PHP也实现一下区块链的简单流程。
phper或其他人如有需要可加PHP区块链交流群(370648191/201923866)。
只有一个类、4个方法。可直接运行。
<?php
/**
* 简单的PHP区块链
* @author Yoper
* @PHP技术交流QQ群 370648191
* @Email chen.yong.peng@foxmail.com
* @wechat YoperMan
*/
namespace common\library\block;
/**
* 区块结构
*/
class block{
private $index;
private $timestamp;
private $data;
private $previous_hash;
private $random_str;
private $hash;
public function __construct($index,$timestamp,$data,$random_str,$previous_hash)
{
$this->index=$index;
$this->time