Landing page code

principle:

Generating a picture, and stores the characters to appear in the image SESSION . Landing determining whether the input check code and the check code SESSION same.

This is generated check code and image files checkNumber.php

<? PHP
 session_start ();
 IF ( $ ACT == "the init" ) 
{ 
    Header ( "Content-of the type: Image / PNG" );
    srand ( microtime () * 100000 );
    $ login_check_number = strval ( RAND ( "1111" , "9999" ));
    the session_register ( "login_check_number" );
    // this is used to hold a check code SESSION. 
    @ course be used COOKIE 
    // the setcookie ( "login_check_number", $ login_check_number); 
    // then session_start first line () to delete; 
    // not recommended COOKIE, COOKIE and can not be because of the use of secure authentication.
    $h_img = imagecreate(40,17);
    $c_black = ImageColorAllocate($h_img, 0,0,0);
    $c_white = ImageColorAllocate($h_img, 255,255,255);
    imageline($h_img, 1, 1, 350, 25, $c_black);
    imagearc($h_img, 200, 15, 20, 20, 35, 190, $c_white);
    imagestring($h_img, 5, 2, 1, $login_check_number, $c_white);
    ImagePng($h_img);
    ImageDestroy($h_img);
    die();
}
/ * Usage: 
adding HTML file <input type = text name = number maxlength = 4> <? Img src = checkNumber.php act = init> add the following PHP code to check the landing page (note: in addition of the code before output can not have, because of the use SESSION) 
// $ number the checksum is the value you entered 
include_once ( "./ checkNumber.php"); 
// check check code 
! if ($ number = $ login_check_number || empty ($ number the)) 
{ 
    Print ( "check code is not correct!"); 
    Die (); 
} 
* / 
>? 

using SESSION questions:

If you turn on the landing page landing after the failure in SESSION, then landing will fail.

The use of COOKIE:

COOKIE is stored in the client, so if you use COOKIE, then might as well do not.

For VBB Forum. After saving checkNumber.php. Modify title MYSQL database template to template data table of contents logincode forumhome_logincode username_loggedout.

Then the member.php

if ($action=="login")

After adding

// test check code 
include_once ( "./checkNumber.php" );
 IF ( $ Number ! = $ Login_check_number || $ Number == "" ) 
{ 
  Print ( "check code is incorrect"! );
  Die () ; 
}

 

dsfaeds

Reproduced in: https: //www.cnblogs.com/JoannaQ/archive/2012/08/20/2647000.html

Guess you like

Origin blog.csdn.net/weixin_34415923/article/details/93058908