最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

PHP連接數(shù)據(jù)庫實現(xiàn)簡單的登錄頁面功能

 更新時間:2023年09月21日 10:22:52   作者:木路露  
這篇文章主要介紹了PHP連接數(shù)據(jù)庫實現(xiàn)簡單的登錄頁面功能,文中的示例代碼講解詳細,對大家的學習或工作有一定的幫助,感興趣的可以了解一下

最后實現(xiàn)結(jié)果如下圖所示:

如果輸入的用戶名或密碼為空,則會彈出對話框提示

如果輸入的用戶名或密碼為空,則會彈出對話框提示

登錄成功頁面:

具體實現(xiàn)代碼如下:

HTML代碼:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>登陸</title>
    <link rel="icon" href="img/denglu-img/loginIcon.png" rel="external nofollow" >
    <link rel="stylesheet" href="CSS/denglu-css.css" rel="external nofollow" >
    <script src="JS/jquery-1.11.0.min.js"></script>
    <link rel="stylesheet" href="CSS/bootstrap.min.css" rel="external nofollow" >
    <script src="JS/bootstrap.min.js"></script>
</head>
<body>
    <div id="box" style="background: url('img/loginBackground.jpg');position:fixed;background-repeat: no-repeat;position:fixed;
    top: 0;left: 0;width:100%;height:100%;min-width: 1000px;z-index:-10;zoom: 1;background-color: #fff;background-repeat: no-repeat;
    background-size: cover;-webkit-background-size: cover;-o-background-size: cover;
    background-position: center 0;"></div>
    <form action="login.php" method="post">
        <div class="login">
            <div class="login_container">
                <div class="login_titles">登錄</div>
                <div class="login_user">
                    <img src="img/denglu-img/user.png">
                    <input name="fusername" id="user" type="text" placeholder="請輸入用戶名" style="width: 300px;">
                </div>
                <div class="login_pwd login_user">
                    <img src="img/denglu-img/pwd.png">
                    <input name="fuserpassword" id="pwd" type="text" placeholder="請輸入密碼" style="width: 300px;">
                </div>
                <!-- 記住密碼 -->
                <div class="login_remenber">
                    <input id="remenber_pwd" type="checkbox" value="1" name="remember" checked> 記住密碼
                    <span class="forgetpsd" style="float: right;"><a href="forget.php" rel="external nofollow" 
                            style="color:#fff;">忘記密碼?</a></span>
                </div>
                <div>
                    <p>
                        <span class="login_submit">
                            <button>登陸</button>
                        </span>
                        <span class="zhuce">
                            <!-- <a href="zhuce.php" rel="external nofollow"  rel="external nofollow" ><input type="button" value="注冊"></a> -->
                            <a href="zhuce.php" rel="external nofollow"  rel="external nofollow" ><input type="button" value="注冊"
                                    style=" width: 100px;opacity: 0.8;text-align: center;color:black;font-size: 16px;margin: 10px 20px;">
                            </a>
                        </span>
                    </p>
                </div>
            </div>
        </div>
    </form>
</body>
</html>

css代碼:

*{
    margin: 0;
    padding: 0;
}
.login{
    position: fixed;
    top:50%;
    left:50%;
    transform: translate(-50%,-50%);
}
.login_title{
    text-align: center;
    margin: 10px 0;
    font-size: 30px;
    color: white;
    font-family: "華文行楷";
}
.login_container{
    padding: 20px 30px;
    background: rgba(0,0,0,0.3);
}
.login_titles{
    margin-bottom: 10px;
    text-align: center;
    font-size: 16px;
    color: #eee;
}
.login_user{
    position: relative;
    margin: 20px 0;
}
.login_user img{
    position: absolute;
    height: 20px;
    top: 50%;
    left: 8px;
    transform: translateY(-50%);
}
.login_user input{
    outline: none;
    border: none;
    padding: 7px 0px 7px 35px;
    width: 300px;
    font-family: "Microsoft soft";
    font-size: 14px;
    opacity: 0.4;
}
.login_remenber{
    font-family: "Microsoft soft";
    font-size: 14px;
    color: #eee;
}
.login_submit button{
    width: 100px;
    opacity: 0.8;
    text-align: center;
    color:black;
    font-size: 16px;
    margin: 10px 20px;
}
.zhuce{
    width: 100px;
    opacity: 0.8;
    text-align: center;
    color:black;
    font-size: 16px;
    margin: 10px 20px;
}
.login_message div{
    background: red;
    opacity: 0.8;
    text-align: center;
    color: white;
    font-size: 16px;
    height: 30px;
    line-height: 30px;
    margin: 10px 0;
    display: none;
    transition:  2s;
}
.login_message{
    -webkit-animation: login_message 2s linear;
    -moz-animation: login_message 2s linear;
    animation:login_message 2s linear;
}

PHP連接數(shù)據(jù)庫:

<?php
// 連接到數(shù)據(jù)庫
$servername = "localhost";
$serverusername = "root";
$serverpassword = "123456";
$dbname = "mybs";
// 創(chuàng)建連接
$conn = new mysqli($servername, $serverusername, $serverpassword, $dbname);
// 檢測連接
// if ($conn->connect_error) {
//     die("連接失敗: " . $conn->connect_error);
// } else {
//     echo "連接成功";
// }
// 驗證表單 登錄信息
//判斷用戶名和密碼是否為空
$fusername = isset($_POST['fusername']) ? $_POST['fusername'] : "";
$fuserpassword = isset($_POST['fuserpassword']) ? $_POST['fuserpassword'] : "";
$remember = isset($_POST['remember']) ? $_POST['remember'] : "";
// $fusername = $_POST["fusername"];
// $fuserpassword = $_POST["fuserpassword"];
// echo $fusername, $fuserpassword;
if (!empty($fusername) && !empty($fuserpassword)) { //建立連接
    $sql = "SELECT username,userpassword FROM `users` WHERE username = '$fusername' and userpassword = '$fuserpassword'";
    $result = $conn->query($sql);
    $row = mysqli_fetch_array($result); //判斷用戶名或密碼是否正確
    if ($fusername == $row['username'] && $fuserpassword == $row['userpassword']) {
        // 創(chuàng)建cookie
        // 過期時間被設(shè)置為一個月(60 秒 * 60 分 * 24 小時 * 30 天)
        $expire = time() + 60 * 60 * 24 * 30;
        setcookie("fusername1", $fusername, $expire);
        setcookie("fuserpassword1", $fuserpassword, $expire);
        //關(guān)閉數(shù)據(jù)庫,可進行頁面跳轉(zhuǎn) 這里為了方便 僅顯示為登錄成功
        // header("Location:personcenter.html");
        echo "登錄成功!";
        mysqli_close($conn);
    } else {
        //用戶名或密碼錯誤,賦值err為1
        echo "<script>alert('用戶名或密碼錯誤,請重新輸入!');location.href='denglu.html';</script>";
    }
} else {
    //用戶名或密碼為空,賦值err為2
    echo "<script>alert('用戶名或密碼不能為空,請重新輸入!');location.href='denglu.html'</script>";
}

所建數(shù)據(jù)庫如下:

這樣我們簡單的登錄頁面就做好了,通過form表單傳遞表單信息,一定要與input的name屬性相匹配才能成功。這里所創(chuàng)建的cookie便于用戶登錄后,向多個頁面?zhèn)鬟f用戶信息。如:在另一個頁面中   $fusername = $_COOKIE["fusername1"]; 來接受cookie所傳遞的值

以上就是PHP連接數(shù)據(jù)庫實現(xiàn)簡單的登錄頁面功能的詳細內(nèi)容,更多關(guān)于PHP數(shù)據(jù)庫登錄頁面的資料請關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

  • php 類中的常量、靜態(tài)屬性、非靜態(tài)屬性的區(qū)別

    php 類中的常量、靜態(tài)屬性、非靜態(tài)屬性的區(qū)別

    這篇文章主要介紹了php 類中的常量、靜態(tài)屬性、非靜態(tài)屬性的區(qū)別與介紹,需要的朋友可以參考下
    2017-04-04
  • php類的自動加載操作實例詳解

    php類的自動加載操作實例詳解

    這篇文章主要介紹了php類的自動加載操作,結(jié)合實例形式詳細分析了php類的自動加載操作相關(guān)函數(shù)與實現(xiàn)技巧,需要的朋友可以參考下
    2016-09-09
  • PHP使用strstr()函數(shù)獲取指定字符串后所有字符的方法

    PHP使用strstr()函數(shù)獲取指定字符串后所有字符的方法

    這篇文章主要介紹了PHP使用strstr()函數(shù)獲取指定字符串后所有字符的方法,結(jié)合實例形式較為詳細的分析了PHP中strstr()函數(shù)用于字符串截取的使用技巧,需要的朋友可以參考下
    2016-01-01
  • 支持png透明圖片的php生成縮略圖類分享

    支持png透明圖片的php生成縮略圖類分享

    這篇文章主要介紹了支持png透明圖片的php生成縮略圖類分享,本文代碼基于GD2圖形庫,實現(xiàn)支持png透明圖片生成縮略圖,需要的朋友可以參考下
    2015-02-02
  • php讀取csv文件并輸出的方法

    php讀取csv文件并輸出的方法

    這篇文章主要介紹了php讀取csv文件并輸出的方法,涉及php中fgetcsv函數(shù)的使用技巧,具有一定參考借鑒價值,需要的朋友可以參考下
    2015-03-03
  • 簡單了解PHP編程中數(shù)組的指針的使用

    簡單了解PHP編程中數(shù)組的指針的使用

    這篇文章主要介紹了簡單了解PHP編程中數(shù)組的指針的使用,這里著重討論了賦值時指針的指向等使用時值得注意的地方,需要的朋友可以參考下
    2015-11-11
  • php數(shù)組索引與鍵值操作技巧實例分析

    php數(shù)組索引與鍵值操作技巧實例分析

    這篇文章主要介紹了php數(shù)組索引與鍵值操作技巧,涉及php數(shù)組的遍歷與索引、鍵值操作的相關(guān)技巧,需要的朋友可以參考下
    2015-06-06
  • 詳解PHP神奇又有用的Trait

    詳解PHP神奇又有用的Trait

    這篇文章主要介紹了PHP神奇又有用的Trait,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2019-03-03
  • PHP開發(fā)API接口簽名生成及驗證操作示例

    PHP開發(fā)API接口簽名生成及驗證操作示例

    這篇文章主要介紹了PHP開發(fā)API接口簽名生成及驗證操作,結(jié)合實例形式較為詳細的分析了PHP開發(fā)API接口簽名生成及驗證操作相關(guān)原理、實現(xiàn)方法與操作注意事項,需要的朋友可以參考下
    2020-05-05
  • PHP Mysql編程之高級技巧

    PHP Mysql編程之高級技巧

    盡管PHP為我們提供了很多函數(shù),但有些東西處理起來還是不很方便。譬如PHP提供的日期時間函數(shù)就很有限。Mysql為我們提供了不少此類的函數(shù)。是否可以利用Mysql函數(shù)來處理PHP程序呢?
    2008-08-08

最新評論

建水县| 大冶市| 老河口市| 五华县| 澄江县| 长泰县| 巨鹿县| 枝江市| 贡嘎县| 海口市| 阿拉善左旗| 唐海县| 台东县| 新平| 丰城市| 永寿县| 襄城县| 安顺市| 湖州市| 龙游县| 德化县| 长宁区| 钦州市| 云南省| 勃利县| 玉田县| 高清| 湖州市| 乃东县| 绵竹市| 公安县| 新宁县| 株洲县| 邯郸市| 襄樊市| 五寨县| 辉南县| 秭归县| 荣昌县| 临桂县| 开江县|