duanfei7508 2016-04-17 20:56
浏览 30

我可以将post.php永久保存吗?

For my website you can visit here at http://desire.site88.net at the very bottom you will see my form. When you finish with the form and press submit the form submits the data to desire.site88.net/post.php . What I'm curious is how do I make it permanent? When the user submits data to post.php I want it to stay there. Not looking for anything secure or unhackable, just something I can use to recruit members. Here is my code

<?php

$username = $_POST['username']; 
$email = $_POST['email']; 
$message = $_POST['message']; 

// what it will say down below
echo $username. ' has an email of </br>'; 

echo $email. ' and wants to join because </br>'; 

echo $message. '</br></br>'; 

<form method="post" action="test.php"> <div class="row 50%"> <div class="6u 12u(mobile)"><input type="text" name="username" placeholder="Username" /></div> <div class="6u 12u(mobile)"><input type="email" name="email" placeholder="Email" /></div> </div> <div class="row 50%"> <div class="12u"><textarea name="message" placeholder="Application" rows="6"></textarea></div> </div> <div class="row"> <div class="12u"> <ul class="actions"> <li><input type="submit" value="submit" /></li> </ul> </div> </div> </form>

  • 写回答

1条回答 默认 最新

  • dro60731 2016-04-17 21:24
    关注

    So reading your previous comment about looking for a simple way to collect data without the need for security, I recommend saving it in a text file for now, and maybe later using XML, which you can investigate into later.

    code to save into a text file:

    $filePath = $username."-".time().".txt";
    $myFile = fopen($filePath, "w");
    fwrite($myFile, ("username: ".$username."
    "));
    fwrite($myFile, ("email: ".$email."
    "));
    fwrite($myFile, ("message: ".$message."
    "));
    fclose($myFile);
    

    that code will save a file with a unique name each time it is saved, and it would be located in the same directory as your php page.

    let me know if that worked for you or if you have any doubts :)

    Edited: Explaining first how the function fopen() works. Placing "w" in the second parameter means the function will create a new file with the information you give it, and if the file already existed, it will re-write it, meaning any previous information that existed in the file will be gone. For this reason, I made the $filePath unique, so that no overwriting happens. I will now go a bit further and include the logs in a new separate file that is outside the root folder for added security:

    //++++ path obtained to your root folder
    $root_directory_path = $_SERVER['DOCUMENT_ROOT'];
    //++++ creating the path for the logs in a new folder outside
    //++++ the root director
    $filePath = $root_directory."/../my_logs/".$username."-".time().".txt";
    
    //++++ starting the creation of the file
    $myFile = fopen($filePath, "w");
    
    //++++ inputing information into the file
    $inputString = "username: ".$username."
    ";
    fwrite($myFile, $inputString);
    
    $inputString = "email: ".$email."
    ";
    fwrite($myFile, $inputString);
    
    $inputString = "message: ".$message."
    ";
    fwrite($myFile, $inputString);
    
    //++++ closing the file / finalizing the creation of the file
    fclose($myFile);
    

    I visited your site and it seems you are having issues with the permissions that the site gives you. If you still wish to user text files inside the root directory, you can follow the code below, however be informed that anyone can view the users that are registered since the information is being saved in a subfolder of the rood directory, so I do recommend transitioning to a database that is secure:

    $filePath = "/myLogs/".$username."-".time().".txt";
    $myFile = fopen($filePath, "w");
    fwrite($myFile, ("username: ".$username."
    "));
    fwrite($myFile, ("email: ".$email."
    "));
    fwrite($myFile, ("message: ".$message."
    "));
    fclose($myFile);
    
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。