PHP simple image verification code implementation
|
// The first code generates a random image ------ code2.php
- // Enable session to save the generated content
- Session_start ();
- $ Table = array (
- "Pic0" => "dog ",
- "Pic1" => "cat ",
- "Pic2" => "fish ",
- "Pic3" => "bird"
- );
- $ Index = rand (0, 3 );
- $ Value = $ table ['Pic '. $ index];
- $ _ SESSION ['authcode'] = $ value;
- // Obtain the randomly generated image name
- $ Filename = dirname (_ FILE _). '/pic'.w.index.'.jpg ';
- $ Content = file_get_contents ($ filename );
- Header ('content-type: image/jpg ');
- Echo $ content;
- ?>
// Verification of the second code line form
- If (isset ($ _ REQUEST ['authcode']) {
- Session_start ();
- If ($ _ REQUEST ['authcode'] == _ SESSION ['authcode']) {
- Echo "right ";
- } Else {
- Echo "sad story
";
- Echo $ _ REQUEST ['authcode'];
- }
- }
- ?>
- ?>
/* The code path is the linux path */
|
Verification code, PHP