如何将用户输入保存为简单的.txt?
我是php的新手,所以请在这里帮助我。
我的代码:
<?php
if(isset($_POST['email']) && isset($_POST['password'])) {
$data = $_POST['email'] . '-' . $_POST['password'] . "\n";
$ret = file_put_contents('/tmp/mydata.txt', $data, FILE_APPEND | LOCK_EX);
if($ret === false) {
die('There was an error writing this file');
}
else {
echo "$ret bytes written to file";
}
}
else {
die('no post data to process');
}
?>
不要认为我需要包含这个但是我发现了一个非常酷的登录表单并改变了当然的名称:
<!DOCTYPE html>
<html >
<head>
<meta charset="UTF-8">
<title>Material Login Form</title>
<link rel="stylesheet" href="css/reset.css">
<link rel='stylesheet prefetch' href='http://fonts.googleapis.com/css?family=Roboto:400,100,300,500,700,900|RobotoDraft:400,100,300,500,700,900'>
<link rel='stylesheet prefetch' href='http://maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css'>
<link rel="stylesheet" href="css/style.css">
</head>
<body>
<!-- Mixins-->
<!-- Pen Title-->
<div class="pen-title">
<h1>Material Login Form</h1></div>
<div class="rerun"><a href="">Rerun Pen</a></div>
<div class="container">
<div class="card"></div>
<div class="card">
<h1 class="title">Login</h1>
<form>
<div class="input-container">
<input name="email" type="text" id="Username" required="required"/>
<label for="Username">Email</label>
<div class="bar"></div>
</div>
<div class="input-container">
<input name="password" type="password" id="Password" required="required"/>
<label for="Password">Password</label>
<div class="bar"></div>
</div>
<div class="button-container">
<button><span>Go</span></button>
</div>
<div class="footer"><a href="#">Forgot your password?</a></div>
</form>
</div>
<div class="card alt">
<div class="toggle"></div>
<h1 class="title">Register
<div class="close"></div>
</h1>
<form>
<div class="input-container">
<input type="text" id="Username" required="required"/>
<label for="Username">Email</label>
<div class="bar"></div>
</div>
<div class="input-container">
<input type="password" id="Password" required="required"/>
<label for="Password">Password</label>
<div class="bar"></div>
</div>
<div class="input-container">
<input type="password" id="Repeat Password" required="required"/>
<label for="Repeat Password">Repeat Password</label>
<div class="bar"></div>
</div>
<div class="button-container">
<button><span>Next</span></button>
</div>
</form>
</div>
</div>
<!-- Portfolio--><a id="portfolio" href="http://andytran.me/" title="View my portfolio!"><i class="fa fa-link"></i></a>
<!-- CodePen--><a id="codepen" href="http://codepen.io/andytran/" title="Follow me!"><i class="fa fa-codepen"></i></a>
<script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script>
<script src="js/index.js"></script>
</body>
</html>
我在这里不知所措,我不知道该修复什么!
答案 0 :(得分:1)
类似这样的内容:
redisClient.Subscribe(elementKey, "expire", DoSomethingBasedOnKey)
答案 1 :(得分:1)
<div class="pen-title">
<h1>Material Login Form</h1></div>
<div class="rerun"><a href="">Rerun Pen</a></div>
<div class="container">
<div class="card"></div>
<div class="card">
<h1 class="title">Login</h1>
<form action="upload.php" method="post">
<div class="input-container">
<input name="email" type="text" id="Username"
required="required"/>
<label for="Username">Email</label>
<div class="bar"></div>
</div>
<div class="input-container">
<input name="password" type="password"
id="Password" required="required"/>
<label for="Password">Password</label>
<div class="bar"></div>
</div>
<div class="button-container">
<button type="submit">Go</button>
</div>
<div class="footer"><a href="#">Forgot your password?
</a></div>
</form>
</div>
</div>
//in php file use this code for saving file
$myfile= fopen('/tmp/mydata.txt','w') or die("Unable to open file!");;
fwrite($myfile,$_POST);//or $data