- <?php
- define("USERS_LOG","users.log");
- if($_SERVER["REQUEST_METHOD"] == "POST"){
- $fn = trim(strip_tags($_POST["fname"]));
- $ln = trim(strip_tags($_POST["lname"]));
- $user = "$fn $ln \\n";
- file_put_contents(USERS_LOG,$user, FILE_APPEND);
- header("Location: test.php");
- exit;
- }
- ?>
- <form action="" method="post">
- <input type='text' name='fname'>
- <input type='text' name='lname'>
- <input type='submit' value='submit it'>
- </form>
- <?php
- if(file_exists(USERS_LOG)){
- $users = file(USERS_LOG);
- if(is_array($users)){
- $users = array_reverse($users);
- echo "<ol>";
- foreach ($users as $user){
- echo "<li>$user</li>";
- }
- echo "</ol>";
- }
- }
- ?>
- //该片段来自于http://www.codesnippet.cn/detail/290920136249.html
来源: http://www.codesnippet.cn/detail/290920136249.html