开发者

php ajax generate voucher

开发者 https://www.devze.com 2023-02-17 22:39 出处:网络
anyone know how to generate voucher code with ajax and php. ive got the html form: <form id=\"g_voucher\" method=\"post\">

anyone know how to generate voucher code with ajax and php.

ive got the html form:

<form id="g_voucher" method="post">
      <h2>Generate Voucher</h2>
      <div class="v_code"></div>
      <input type="submit" value="Generate" />
</form>

ajax jquery???:

$('#g_voucher').submit(function(e){
  $.post('include/voucher.php?g_voucher', { },

  e.preventDefault();
}

for PHP will use simple code:

$v_code = substr(md5($_SERVER['REMOTE_ADDR'].microtime().rand(1,999999)),0,10)开发者_StackOverflow社区;

everytime i click submit button, it will keep generating new code..


You could store the voucher in the session, and when generating a new voucher check if the session already contains a voucher.

session_start();
if(isset($_SESSION['voucher'])) {
  return $_SESSION['voucher'];
}

Although this code will result in a new voucher each time the session is terminated (browser closed basically). To achieve a more permanent voucher, you should have some sort of client authentication + database to store the generated voucher.

0

精彩评论

暂无评论...
验证码 换一张
取 消