激战的后厨2观看完整版,強姦亂倫強姦在线观看,国产无套内射普通话对白,老头呻吟喘息硕大撞击,他扒开我小泬添我三男一女视频

廈門服務器租用>>php實現會員登陸注冊頁有html加Session和Cookie

php實現會員登陸注冊頁有html加Session和Cookie

發布時間:2022/8/18 17:27:00    來源: 縱橫數據

用戶注冊信息,管理員核對信息審核通過后,可實現注冊的用戶名和密碼的成功登陸,利用session和cookie獲取用戶信息并且不能跳過登錄頁面直接進入主頁面

1.Session
存儲在服務器
可以存儲任何內容
有默認過期時間:大約15分鐘
相對比較安全
用法:
1.必須在php頁面開始寫:session_start();開啟session
2.寫Session: $_SESSION["uid"]=$uid;
3.讀取Session:$_SESSION["uid"];

2.Cookie
存儲在客戶端
只能存儲字符串
默認沒有過期時間
用法:
1.設置Cookie:setcookie("name","value");
2.取值:$_COOKIE["name"];

在php里面寫
目的:
獲取用戶信息
不能跳過登陸頁面

zhuce.php


2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "//www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="//www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>無標題文檔</title>
<script type="text/javascript" src="jquery-2.1.4.min.js"></script>
</head>
<body>
<p style="background-color:#CCC; width:300px; padding-left:10px;">
<h1>注冊頁面</h1>
<p>用戶名:<input type="text" id="uid" /></p><br />
<p>密&nbsp;&nbsp;碼:<input type="text" id="pwd" /></p><br />
<p>姓&nbsp;&nbsp;名:<input type="text" id="name" /></p><br />
<p>性&nbsp;&nbsp;別:<input type="radio" checked="checked" name="sex" id="nan" value="true" />男&nbsp;<input type="radio" name="sex" value="false" />女</p><br />
<p>生&nbsp;&nbsp;日:<input type="text" id="birthday" /></p><br />
<p>工&nbsp;&nbsp;號:<input type="text" id="code" /></p><br />
<p><input type="button" value="提交" id="btn" />&nbsp;&nbsp;&nbsp;<input type="button" value="查看" onclick="window.open('main.php')" /></p><br />
</p>
</body>
<script type="text/javascript">
$(document).ready(function(e) {
    $("#btn").click(function(){
        var uid = $("#uid").val();
        var pwd = $("#pwd").val();
        var name = $("#name").val();
         
        var sex = $("#nan")[0].checked;
         
        var birthday = $("#birthday").val();
        var code = $("#code").val();
        $.ajax({
            url:"zhucechuli.php",
            data:{uid:uid,pwd:pwd,name:name,sex:sex,birthday:birthday,code:code},
            type:"POST",
            dataType:"TEXT",
            success: function(data){
                if(data=="OK")
                {
                    alert("注冊成功!");
                    }
                else
                {
                    alert("注冊失敗!");
                    }
                 
                }
             
              })
         
        })   
});
</script>
</html>

zhucechuli.php

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<?php
$uid=$_POST["uid"];
$pwd=$_POST["pwd"];
$name=$_POST["name"];
$sex=$_POST["sex"];
$birthday=$_POST["birthday"];
$code=$_POST["code"];
 
include("mydbda.php");
$db = new mydbda();
$sql="insert into users values('".$uid."','".$pwd."','".$name."',".$sex.",'".$birthday."','".$code."',false)";
$str = $db->Select($sql,"QT","mydb");
echo $str;
 
?>

main.php

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?php
session_start();
//找session
if(empty($_SESSION["uid"]))
{
    header("Location:denglu.php");//定義不能跳轉頁面
    }
//找coolie
//$_COOKIE["uid"]   
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "//www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="//www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>無標題文檔</title>
</head>
 
<body>
<h1>注冊審核頁面 </h1>
<table width="100%" border="1" cellpadding="0" cellspacing="0">
<tr>
    <td>用戶名</td>
    <td>密碼</td>
    <td>姓名</td>
    <td>性別</td>
    <td>生日</td>
    <td>工號</td>
    <td>狀態</td>
</tr>
<?php
  include("mydbda.php");
  $db=new mydbda();
  $sql="select * from users";
  $str=$db->Select($sql,"CX","mydb");
  $hang=explode("|",$str);
  for($i=0;$i<count($hang);$i++)
     {
         $lie=explode("^",$hang[$i]);
         $sex=$lie[3]?"男":"女";
         $zhuangtai=$lie[6]?"<input type='text' value='審核已通過' checked='checked'/>":"<a href='shenhechuli.php?uid={$lie[0]}'>審核</a>";
         echo "<tr>
               <td>{$lie[0]}</td>
               <td>{$lie[1]}</td>
               <td>{$lie[2]}</td>
               <td>{$sex}</td>
               <td>{$lie[4]}</td>
               <td>{$lie[5]}</td>
               <td>{$zhuangtai}</td>
              </tr>";
         }
 
?>
</table>
</body>
</html>

shehechuli.php

1
2
3
4
5
6
7
8
9
10
<?php
 include("mydbda.php");
 $uid=$_GET["uid"];
  
 $db=new mydbda();
 $sql="update users set isok=true where uid='".$uid."'";
 $str=$db->Select($sql,"QT","mydb");
 header("Location:main.php");
 
?>

denglu.php

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "//www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="//www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>無標題文檔</title>
</head>
 
<body>
<p style="width:300px; background-color:#CCC">
<h1>登陸頁面</h1>
 
<form action="dengluchuli.php" method="post">
<p>用戶名:<input type="text" name="uid" /></p><br />
 
<p>密&nbsp;&nbsp;碼:<input type="text" name="pwd" /></p><br />
<p><input type="submit" value="登陸"  /></p>
</form></p>
</body>
</html>

dengluchuli.php

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
<?php
session_start();//開啟Session 寫在php里 必須寫在最上面
 
$uid = $_POST["uid"];
$pwd = $_POST["pwd"];
include("mydbda.php");
$db=new mydbda();
 
$sql="select count(*) from users where uid='".$uid."' and pwd='".$pwd."' and isok =true";
 
$str = $db->Select($sql,"CX","mydb");
if($str==1)
{
    $_SESSION["uid"]=$uid;//存在服務器,任何頁面都可以調用
    //$_SESSION["name"]=array(1,2,3,4,5)session可以存儲任何內容
    //用cookie寫
    //setcookie("uid",$uid);//定義cookie 會在客戶端生成cookie文件
     
    header("Location:main.php");
    }
else
{
    header("Location:denglu.php");
    }   
?>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<?php
    class mydbda
    {
        var $host = "localhost";
        var $username = "root";
        var $password = "123";
        var $database = "mydb";
         
        /**
            功能:執行SQL語句,返回結果
            參數:$sql:要執行的SQL語句
                 $type:SQL語句的類型,CX代表查詢,QT代表其他
                 $data:要操作的數據庫
            返回值:如果是查詢,返回結果集
                  如果是其他語句,執行成功返回OK,失敗返回NO
        */
        function Select($sql,$type,$data)
        {
             
            //1.造連接對象
            $db = new mysqli($this->host,$this->username,$this->password,$data);
             
            //2.判斷是否連接成功
            if(mysqli_connect_error())
            {   
                echo "連接失敗";
                 
                //退出整個程序
                exit;
            }
            else
            {
                //4.執行SQL語句
                 
                $result = $db->query($sql);
                 
                if($type == "CX")
                {
                    $str = "";
                     
                    while($row = $result->fetch_row())
                    {
                        for($i=0;$i<count($row);$i++)
                        {
                            $str=$str.$row[$i]."^";
                        }
                        $str = substr($str,0,strlen($str)-1);
                        $str = $str."|";
                         
                    }
                    $str = substr($str,0,strlen($str)-1);
                    return $str;
                }
                else
                {
                    if($result)
                    {
                        return "OK";
                    }
                    else
                    {
                        return "NO";
                    }
                }
                 
         
            }
        }
 
         
     
    }
?>
 
mydbda.php


上一篇:沒有了
下一篇:沒有了
在線客服
微信公眾號
免費撥打400-1886560
免費撥打0592-5580190 免費撥打 400-1886560 或 0592-5580190
返回頂部
返回頭部 返回頂部