Php graphic code for sign-in

Source: Internet
Author: User
First, I created two tables in the database. one is the user's integral table and the other is the sign-in status table, to record the number of credits and first-come status of a user, I first created two tables in the database. one is the user's integral table and the other is the sign-in status table, used to record the number of credits and the first-come status of a user

In the user sign-in status table, we have a field, last_sign_time, that is, the last sign-in time. each time we sign in, we can compare this time with the current time. if the difference is 0 days, it indicates that you have signed in today (this sign-in can only be performed once within 24 hours, that is, the two sign-in times must differ by more than 24 hours ). if it is equal to one day, you can sign in today. if it is 2 days or more, the signature is missing.

Based on the timestamp, the status table is updated in a timely manner, and user points are updated when you can sign in.

 $ Days, "hour" =>$ hours, "min" =>$ mins, "sec" =>$ secs); return $ res;} function upuserscore ($ current_total_day) {$ user_id = @ $ _ REQUEST ['User _ id']; // The INI file for reading database configuration information $ ary = parse_ini_file ('Db. ini '); $ db_login_name = base64_decode ($ ary ['DB _ login_name']); $ db_login_password = base64_decode ($ ary ['DB _ login_password ']); $ db_host = base64_decode ($ ary ['DB _ host']); $ db_name = base64_decode ($ ary ['DB _ name']); // link to the database $ scorelin K = mysqli_connect ($ db_host, $ db_login_name, $ db_login_password); mysqli_select_db ($ scorelink, $ db_name ); // SELECT database // check whether the user exists in the integral table. if no data is updated, insert the Data $ scoreq = "SELECT * FROM user_score WHERE user_id = $ user_id "; // SQL INSERT statement mysqli_query ($ scorelink, "SET NAMES utf8"); $ rs = mysqli_query ($ scorelink, $ scoreq); // Obtain the dataset if (! $ Rs) {exit (json_encode (array ('status' => "success", 'code' => "1 ", 'Error' => mysqli_error ($ scorelink);} if (mysqli_num_rows ($ rs )) {// if the user has data, the points are updated. $ total_score = ""; while ($ row = mysqli_fetch_row ($ rs) {$ total_score = $ row [4];} $ scoreusdateq = "UPDATE user_score SET user_total_score = '98 'WHERE user_id = $ user_id;"; // UPDATE mysqli_query ($ scorelink, "set names utf8 "); $ ustaters = mysqli_query ($ scorelink, $ score Usdateq); // Obtain the dataset if ($ ustaters = 1) {exit (json_encode (array ('status' => "success ", 'code' => "100"); mysqli_close ($ scorelink); // close the connection exit ();} else {exit (json_encode (array ('status' => "success", 'code' => "1"); mysqli_close ($ scorelink ); // close the connection exit () ;}} else {// if this user data does not exist, insert the point information $ scoreinsertq = "insert into user_score (user_id, user_total_score) values ($ user_id, 10) "; // SQL INSERT statement mysqli_query ($ scorelink," SET NA MES utf8 "); $ rs = mysqli_query ($ scorelink, $ scoreinsertq); // Obtain the dataset if (! $ Rs) {exit (json_encode (array ('status' => "success", 'code' => "1 ", 'Error' => mysqli_error ($ scorelink);} if (strpos ($ q, "SELECT") = false) {exit (json_encode (array ('status' => "success", 'code' => "100");} mysqli_close ($ scorelink ); // close the connection} // The INI file that reads the database configuration information $ ary = parse_ini_file ('Db. ini '); $ db_login_name = base64_decode ($ ary ['DB _ login_name']); $ db_login_password = base64_decode ($ ary ['DB _ login_password ']); $ db_h Ost = base64_decode ($ ary ['DB _ host']); $ db_name = base64_decode ($ ary ['DB _ name']); // link database $ link = mysqli_connect ($ db_host, $ db_login_name, $ db_login_password); mysqli_select_db ($ link, $ db_name ); // SELECT database // check whether the user exists in the sign-in table. if no data is updated, insert the Data $ q = "SELECT * FROM user_signin WHERE user_id = $ user_id "; // SQL INSERT statement mysqli_query ($ link, "SET NAMES utf8"); $ rs = mysqli_query ($ link, $ q); // Obtain the dataset if (! $ Rs) {exit (json_encode (array ('status' => "success", 'code' => "1 ", 'Error' => mysqli_error ($ link);} if (mysqli_num_rows ($ rs )) {// if the user has data, update his/her sign-in information $ last_time = ""; $ total_day = ""; while ($ row = mysqli_fetch_row ($ rs )) {$ last_time = $ row [4]."
"; $ Total_day = $ row [5];} // compare the last sign-in time with the current sign-in time to determine whether there is a missing sign or whether the current sign-in is $ current_total_day = intval ($ total_day) + 1; $ current_day = time (); $ ary = timediff ($ last_time, $ current_day); if ($ ary [day] = 0) {// exit (json_encode (array ('status' => "success", 'code' => "5"); mysqli_close ($ link ); // close the connection exit ();} else if ($ ary [day] = 1) {// no signature missing $ usdateq = "UPDATE user_signin SET last_sign_time = '$ current_day', total_day = '$ current_t Otal_day 'Where user_id = $ user_id; "; // update mysqli_query ($ link," set names utf8 "); $ ustaters = mysqli_query ($ link, $ usdateq ); // Obtain the dataset if ($ ustaters = 1) {upuserscore ($ current_total_day); // exit (json_encode (array ('status' => "success ", 'code' => "100"); mysqli_close ($ link); // close the connection exit ();} else {exit (json_encode (array ('status' => "success", 'code' => "1"); mysqli_close ($ link ); // close connection exit () ;}} else {// missed $ usdat Eq = "UPDATE user_signin SET last_sign_time = '$ current_day', total_day = 1 WHERE user_id = $ user_id;"; // UPDATE mysqli_query ($ link, "set names utf8 "); $ ustaters = mysqli_query ($ link, $ usdateq); // Obtain the dataset if ($ ustaters = 1) {upuserscore ($ current_total_day ); // exit (json_encode (array ('status' => "success", 'code' => "100"); mysqli_close ($ link ); // close the connection exit ();} else {exit (json_encode (array ('status' => "success", 'code' =>" 1 "); mysqli_close ($ link); // close the connection exit () ;}} else {// Insert $ current_day = time () if the user record does not exist (); $ insertq = "insert into user_signin (user_id, last_sign_time, total_day) values ($ user_id, '$ current_day', 1)"; // SQL insert statement mysqli_query ($ link, "set names utf8"); $ insertrs = mysqli_query ($ link, $ insertq); // Obtain the dataset if (strpos ($ insertrs, "SELECT") = false) {// data entry/exit succeeded upuserscore ('1'); // exit (json_encode (array ('status' => "succes S ", 'code' =>" 100 ") ;}} mysqli_close ($ link); // close the connection?>

The above is a detailed description of the graphic code for php to implement the sign-in function. For more information, see PHP Chinese network (www.php1.cn )!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.