将信息从URL发送到文件,PHP


Sending information from URL to file, PHP

研究C#并在一个代码示例中注意到这一点:

namespace my_program
{
    public partial class Form1 : Form
    {
        //Url to send username, computer name and computer info
        string targetURL = "https://www.example.com/my_program/write.php?info=";
        string userName = Environment.UserName;
        string computerName = System.Environment.MachineName.ToString();
        string userDir = "C:''Users''";

我不知道write.php在服务器上由什么代码组成。所以我的问题是:为了保存URL中提供的信息,在/write.php之后?info=,在我的服务器上的文本文件中,我该如何用php进行编码?我相信这是非常基本的,但对我来说是新的东西。

php文件中,您可以使用函数fwrite或其别名fputs

假设您在C#中的url为https://www.example.com/my_program/write.php?info=WriteThisNow"

下面是一个应该让你进入php 的例子

<?php
$string = $_GET['info']; // take the value of the GET superglobal
$handle = fopen('output.txt', 'w'); // open a handler to a file for writing
fputs($handle, $string); // write the contents of the $string variable to the file
fclose($handle); // close the handler

现在您所需要的只是Apache或Nginx对文件系统拥有写入权限,并且您的文件应该在php文件旁边创建,文件中包含内容。