php中保存表单数据到本地text文件

表单提交登录页:

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>登录页面</title>
    <!--havcom图标引入-->
    <link rel="shortcut icon" href="网页图标.ico">

<link href="css/login.css" rel="stylesheet" type="text/css">
<style>
    body {
        background-image: url("images/666.jpg");
        background-repeat: no-repeat;
        background-size:100% 100%;
        background-attachment:fixed;
    }
</style>

</head>

<body>
    <div class="login">
        <div class="login-concent">Login</div>
        <div class="user">
            <form name="login" action="index.php" method="post">
                <input type="text" name="user" size="30" required autofocus placeholder="2-16位用户" pattern="^[\u4e00-\u9fa5a-zA-Z0-9_-]{2,16}$" class="input-item">
               
               <input type="password" name="password" size="30" required placeholder="不少于6位密码" pattern="^[\w!@#$%^&*?-]{6,}$" class="input-item">
                <input type="submit" value="登录" class="log-but">
            </form>
           
        </div>
    </div>
</body>

</html>

表单信息保存text页面代码:index.php

<?php
    $user=trim($_POST['user']);
    $password=trim($_POST['password']);
    if(!$user || !$password){
        echo 'please make sure no empty input';
        exit;
    }
    //write to test.txt
    $handle=fopen('test.txt','a+');//打开该文件,以读写的方式
    
    fwrite($handle,'$user:'.$user.'-----'.'$password:'.$password."\r\n");//在打开的文件中写入内容

    fclose($handle);//关闭数据流
?>

总结:

在这里插入图片描述

  • 1
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值