单击文本标记以生成新哈希 [英] Clicking a text tag to generate new hash

查看:62
本文介绍了单击文本标记以生成新哈希的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

$num = rand(0, 10000);
$hash = password_hash($num, PASSWORD_BCRYPT, array(
    'cost' => 6
));

以上是哈希值

<p class="reg-code">Hash: <span><?php echo $hash; ?></span><i class="fa fa-refresh" aria-hidden="true" id="refresh-code"></i></p>

我希望如此,当有人点击标签时,它会在跨度中生成新的哈希,我怎么会碰到这个?

I would like it so when someone clicks on the tag that it generates a new hash into the span, how would I come across this?

我不知道我会怎么做,比如PHP中的函数或什么。

I'm not sure how I would do this, like as a function in PHP or what.

推荐答案

它叫做Ajax:

<p class="reg-code">
  Hash: 
  <span id="hash"><?php echo $hash; ?></span>
  <i id="click" class="fa fa-refresh" aria-hidden="true" id="refresh-code"></i>
</p>

$('#click').click(function(){
  $.post( "./path/to/hashscript.php", function( data ) {
    $( "#hash" ).html( data );
  });
});

您使用JavaScript事件发出服务器请求并使用响应更新页面元素。您的PHP脚本应该回显 $ hash

You use JavaScript events to make a server request and update the page elements with the response. Your PHP script should echo the $hash.

echo password_hash($num, PASSWORD_BCRYPT, ['cost' => 6]);

这篇关于单击文本标记以生成新哈希的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆