Joke Collection Website - Public benefit messages - How to use javascript code to judge whether the verification code entered by the user in php is correct?
How to use javascript code to judge whether the verification code entered by the user in php is correct?
& ltscript type = " text/JavaScript " & gt;
var xmlHttp
Function createXMLHttpRequest ()
{
If (window. ActiveXObject)
{
xmlHttp = new ActiveX object(" Microsoft。 XMLHTTP”);
}
Else if (window. XMLHttpRequest)
{
xmlHttp = new XMLHttpRequest();
}
}
Function doit ()
{
createXMLHttpRequest();
xmlhttp . onreadystatechange = handleStateChange;
xmlHttp.open("get "," auth_code.php ",true);
xmlhttp . send(null);
}
Function handleStateChange ()
{
if(xmlHttp.readyState==4)
{
if(xmlhttp . status = = 200 | | xmlhttp . status = = 0)
{
checkAuthCodeInput(xmlhttp . responsetext);
}
}
}
Function checkAuthCodeInput(authcode)
{
if(document . getelementbyid(" custom ")。 Value = = verification)
{
Return true
}
Returns false
}
& lt/script & gt;
& ltimg src = " auth _ code . PHP " id = " img _ auth _ code "/& gt;
& lta href = " document . getelementbyid(' img _ auth _ code ')。 src='auth_code.php? code = '+math . random();" & gt I can't see clearly. Please change it.
//This page is used to randomly obtain the verification code rand _ auth _ code.php.
& lt? Server-side programming language (abbreviation of professional hypertext preprocessor)
The function get_auth_code ()
{
for($ I = 0; $ i & lt5; $i++)
{
$_GLOBALS['rand_str']。 =strtoupper(dechex(rand(0, 15)));
rand _ str _ width+= imagefontwidth($ I);
}
}
echo $ _ GLOBALS[' rand _ str '];
& gt
& lt? Server-side programming language (abbreviation of professional hypertext preprocessor)
include _ once(" rand _ auth _ code . PHP "); //Import the page that generates the verification code.
$ img _ width = 100;
$ img _ height = 25
$ img = imagecreatetruecolor($ img _ width,$ img _ height);
$ img _ BG _ color = imagecolorlallocate($ img,0,0,0);
imagefill($img,0,0,$ img _ BG _ color);
$ img _ font _ color = imagecolorlocate($ img,225,225,225);
get_auth_code()。 //Call the method to generate a random verification code.
$ img _ font _ x = $ img _ width/2-$ rand _ str _ width/2;
$ img _ font _ y =($ img _ height-imagefont width(5))/2;
imagestring($img,5,$img_font_x,$img_font_y,$_GLOBALS[rand_str],$ img _ font _ color);
Header ("content-type: image/JPEG");
image JPEG($ img);
image destroy($ img);
unset($ _ GLOBALS[' rand _ str ']);
& gt
I wonder if it meets your requirements.
- Previous article:Christmas wishes warm people's hearts.
- Next article:How to activate Suzhou bank card on mobile phone
- Related articles
- Document No.20 18 54 issued by the Ministry of Human Resources and Social Security: Notice on the Total Cancellation of Retirees' Centralized Certification
- Dissatisfied with mobile practices
- Is there any software on the computer that can send short messages for free?
- Why can't I find the text message I sent?
- How to inform the tenant to raise the rent is better?
- Urgent: the detailed process of motorcycle entering the home in Dongshan District, Jieyang City! (I have my own spare time to run into the house, and I don't want the scalper to run errands to make mo
- Save a woman's heart, save a girlfriend's touching words.
- Blessing information for friends and things.
- How about a card? Who knows? I am a chain store in the north, and I need better management of members to form a one-card style;
- I deliver the express. What if the courier is lost?