5.31 PHP会话技术

利用cookie统计访问次数

<?php
    header("Conten-type:text/html;Charset=utf-8");
    if(!isset($_COOKIE['visits'])){
        $visits = 1;
        setcookie('visits',$visits,time()+3600*24*365);
    }
    else{
        $visits = $_COOKIE['visits']+1;
        setcookie('visists',$visits,time()+3600*24*365);
    }
    echo "这是第{$visits}次访问"."<br>";
?>

获取文本框输入的值

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>获取文本框输入值</title>
</head>
<body>
    <form action="" method="post">
        用户名:<input type="text" name="username" size="20" />
        密&nbsp;&nbsp;码:<input type="password" name="usserpwd" size="20" />
        <input type="submit" name="submit" value="提交" />
    </form>
</body>
</html>
<php>
    error_reporting(0);
    if($_POST['username']!=""&&$_POST['userpwd']!=""){
        $username = $_POST['username'];
        $userpwd = $_POST['userpwd'];
        echo "您输入的用户名为:".$username."&nbsp;&nbsp;密码为:".$userpwd."<br>";
    }
</php>
posted @ 2023-05-31 23:30  N0zoM1z0  阅读(18)  评论(0编辑  收藏  举报