douba8048 2009-05-16 08:14
浏览 58
已采纳

PHP:从javascript重新加载验证码图像

I have a user registration form in PHP .I put captcha image check in the page.I used it like this

<img src="captcha.php" alt="Enter this text in the adjacent text box" id="imgCaptcha" />

and in my javascript i will validate this with the same number which is generated in the image (from captcha.php page) . That number was set in a session variable too. Now i want to reload the image to another image from my javascript , if the validattion fails .Is there any way to do so ?

In my captcha.php page,I am creating a Number randomly and then creating an image using imagejpeg. I set this number (in the image) to as session varible also

Please guide me to solve this

Thanks in advance

  • 写回答

1条回答 默认 最新

  • doudan1123 2009-05-16 08:36
    关注

    You need to inject captcha.php into the page using ajax. There are several ways to do this:

    • javascript using XHR but this can be a pain. Here is an example.
    • jQuery provides a simple way to do this, for example:

      $('#someButton').click(function() { $('#someDiv').load('captcha.php'); });

    • prototype.js is a bit more verbose, but does the job. Example.

    I would suggest using jQuery, there are great examples in the docs.

    If your registration page returns on a validation error, you do not need to use javascript for the captcha to get reloaded, that should happen automatically.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 51单片机中C语言怎么做到下面类似的功能的函数(相关搜索:c语言)
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序
  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起