<?php /** * Created by PhpStorm. * User: knowthis * Date: 15/11/18 * Time: 15:04 */ include "config/config.php"; $username = "******"; $password = "******"; $password_data = pass_md5($password); $sql = "insert into blog_admin ( ba_username, ba_nickName, ba_password, ba_email, ba_createTime) VALUE (\n'{$username}','benbentime','{$password_data}','*****@*****.**',NOW()\n)"; $re = mysqli_query($conn, $sql);
function admin_login() { global $conn; $username = strip_tags($_POST['username']); $password = pass_md5($_POST['password']); $sql = "select id from blog_admin where ba_username='******' and ba_password='******'"; $re = mysqli_query($conn, $sql); $num = mysqli_num_rows($re); if ($num) { /* * 存储token */ $row = mysqli_fetch_array($re); $user_id = $row['id']; $time = time(); $token = pass_md5($time . $user_id); $END_date = date('Y-m-d', strtotime('+30 day')); $sql_insert = " insert into blog_token ( bt_token, bt_start, bt_end,bt_user) VALUES ('{$token}',NOW(),'{$END_date}','{$user_id}')"; mysqli_query($conn, $sql_insert); setcookie("token", $token, time() + 3600 * 24 * 7 * 30, "/"); $username_md5 = md5("username"); $aes = new AES("abcdefgh12345678"); $username_string = $aes->encrypt($username); setcookie($username_md5, $username_string, time() + 3600 * 24 * 7 * 30, "/"); echo 1; } else { echo 0; } }