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

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

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

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

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

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

登錄成功頁(yè)面:

具體實(shí)現(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="請(qǐng)輸入用戶名" 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="請(qǐng)輸入密碼" 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="注冊(cè)"></a> -->
                            <a href="zhuce.php" rel="external nofollow"  rel="external nofollow" ><input type="button" value="注冊(cè)"
                                    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ù)庫(kù):

<?php
// 連接到數(shù)據(jù)庫(kù)
$servername = "localhost";
$serverusername = "root";
$serverpassword = "123456";
$dbname = "mybs";
// 創(chuàng)建連接
$conn = new mysqli($servername, $serverusername, $serverpassword, $dbname);
// 檢測(cè)連接
// if ($conn->connect_error) {
//     die("連接失敗: " . $conn->connect_error);
// } else {
//     echo "連接成功";
// }
// 驗(yàn)證表單 登錄信息
//判斷用戶名和密碼是否為空
$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
        // 過(guò)期時(shí)間被設(shè)置為一個(gè)月(60 秒 * 60 分 * 24 小時(shí) * 30 天)
        $expire = time() + 60 * 60 * 24 * 30;
        setcookie("fusername1", $fusername, $expire);
        setcookie("fuserpassword1", $fuserpassword, $expire);
        //關(guān)閉數(shù)據(jù)庫(kù),可進(jìn)行頁(yè)面跳轉(zhuǎn) 這里為了方便 僅顯示為登錄成功
        // header("Location:personcenter.html");
        echo "登錄成功!";
        mysqli_close($conn);
    } else {
        //用戶名或密碼錯(cuò)誤,賦值err為1
        echo "<script>alert('用戶名或密碼錯(cuò)誤,請(qǐng)重新輸入!');location.href='denglu.html';</script>";
    }
} else {
    //用戶名或密碼為空,賦值err為2
    echo "<script>alert('用戶名或密碼不能為空,請(qǐng)重新輸入!');location.href='denglu.html'</script>";
}

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

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

以上就是PHP連接數(shù)據(jù)庫(kù)實(shí)現(xiàn)簡(jiǎn)單的登錄頁(yè)面功能的詳細(xì)內(nèi)容,更多關(guān)于PHP數(shù)據(jù)庫(kù)登錄頁(yè)面的資料請(qǐng)關(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類的自動(dòng)加載操作實(shí)例詳解

    php類的自動(dòng)加載操作實(shí)例詳解

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

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

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

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

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

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

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

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

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

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

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

    詳解PHP神奇又有用的Trait

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

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

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

    PHP Mysql編程之高級(jí)技巧

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

最新評(píng)論

松原市| 蓬安县| 哈巴河县| 安图县| 班玛县| 招远市| 民丰县| 南华县| 栾城县| 西吉县| 鹿泉市| 略阳县| 迭部县| 红河县| 仪陇县| 揭阳市| 柘荣县| 宝山区| 班玛县| 正阳县| 饶河县| 娱乐| 合作市| 喜德县| 麻阳| 龙州县| 乾安县| 黔西县| 新田县| 教育| 饶平县| 阿拉尔市| 新源县| 淮滨县| 基隆市| 云梦县| 南皮县| 万年县| 哈巴河县| 玉林市| 青铜峡市|