Blogger Information
Blog 32
fans 0
comment 0
visits 19926
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
0420
XuanGG的博客
Original
714 people have browsed it

// index文件

实例

<?php




header('location','http://www.baidu.com');
$page_title = '首页';

include("/inc/header.php");


echo '<h2 style="color:red;">我是首页</h2>';
echo "<a href='login_page.php' style='text-align: center'>登陆</a>";



include ('inc/footer.php')



?>

运行实例 »

点击 "运行实例" 按钮查看在线实例



login :

实例

<?php
/**
 * Created by PhpStorm.
 * User: xuan
 * Date: 2018/5/31
 * Time: 20:04
 */
//登陆判断脚本
header("Content-type:text/html;charset=utf-8");
include('inc/connect.php');

include('inc/function.php');

list($check,$data) =user_login($dbs);

if($check) {
    setcookie('user_id', $data['user_id']);
    setcookie('user_name', $data['user_name']);
    url($page='login_in.php');

}


?>

运行实例 »

点击 "运行实例" 按钮查看在线实例

实例

<?php
/**
 * Created by PhpStorm.
 * User: xuan
 * Date: 2018/5/31
 * Time: 20:04
 */
//登陆判断脚本
header("Content-type:text/html;charset=utf-8");
include('inc/connect.php');

include('inc/function.php');

list($check,$data) =user_login($dbs);

if($check) {
    setcookie('user_id', $data['user_id']);
    setcookie('user_name', $data['user_name']);
    url($page='login_in.php');

}


?>

运行实例 »

点击 "运行实例" 按钮查看在线实例


login_in  

实例

<?php
/**
 * Created by PhpStorm.
 * User: xuan
 * Date: 2018/6/1
 * Time: 0:24
 */
header("Content-type:text/html;charset=utf-8");


if(!isset($_COOKIE['user_id'])){
    require('inc/function.php');
    url();


}

include('inc/header.php');

echo <<< "WELCOME"
<h2 style="color: red">登陆成功</h2>
<p>欢迎您:{$_COOKIE['user_name']}</p>





WELCOME;



echo '<a href="index.php">退出</a>';

include('inc/footer.php')



?>

运行实例 »

点击 "运行实例" 按钮查看在线实例


login_page

实例

<?php
/**
 * Created by PhpStorm.
 * User: xuan
 * Date: 2018/5/31
 * Time: 15:25
 */
header("Content-type:text/html;charset=utf-8");


$page_title = '登陆页面';
include('inc/header.php');
?>
<form action="login.php" method="post" xmlns="http://www.w3.org/1999/html">
    <p>
        <label for="email">邮箱</label>
        <input type="text" name="email" id="email">
    </p>

    <p>
        <label for="passwd">密码</label>
        <input type="password" name="passwd" id="passwd">
    </p>
    <input type="submit" >

</form>




<?php
include ('inc/footer.php');
?>

运行实例 »

点击 "运行实例" 按钮查看在线实例


inc 部分 

// database config

实例

<?php
/**
 * Created by PhpStorm.
 * User: xuan
 * Date: 2018/5/31
 * Time: 15:45
 */

define('DB_HOST','127.0.0.1');
define('DB_USER','root');
define('DB_PASS','root');
define('DB_NAME', 'php');
define('DB_CHAR','utf8');

header('Location','http://www.baidu.com');

$dbs = @mysqli_connect(DB_HOST,DB_USER,DB_PASS);

if(mysqli_connect_errno($dbs)){
    Header("Location: http://www.baidu.com");
exit();
}
mysqli_select_db($dbs,DB_NAME);
mysqli_set_charset($dbs,DB_CHAR);

?>

运行实例 »

点击 "运行实例" 按钮查看在线实例

公共函数 和头底部

实例

<?php
/**
 * Created by PhpStorm.
 * User: xuan
 * Date: 2018/5/31
 * Time: 20:05
 */
 include ('connect.php');


 function url($page='index.php'){
     $url = 'http://'.$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']);
    $url = rtrim($url,'/\\');
     $url.= '/'.$page;
    header('Location:'. $url);
    exit();


 }








function user_login($dbs){
    $e = trim($_POST['email']);
    $p= trim($_POST['passwd']);


    $sql = "SELECT `user_id`,`user_name` FROM `user` WHERE `email`='$e' AND `password`=sha1('$p') ";
    // 带入查询
   $query =mysqli_query($dbs, $sql);
$result = mysqli_num_rows($query);

if($result == 1){
    $row = mysqli_fetch_array($query, MYSQLI_ASSOC);
    return [true, $row];

}else{
    echo '账号密码错误';
}




}

运行实例 »

点击 "运行实例" 按钮查看在线实例

实例

<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>
        <?php
        echo isset($page_title ) ? $page_title : '默认标题';

        ?>




    </title>
</head>
<body>
<h3 style="color: fuchsia" >我是头部文件代码</h3>

运行实例 »

点击 "运行实例" 按钮查看在线实例

实例

<h3 style="color: aqua">我是底部代码</h3>
</body>
</html>

运行实例 »

点击 "运行实例" 按钮查看在线实例



Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post