如何制作一个php脚本来创建一个html文件?

时间:2022-01-12 00:14:48

Well.... I want to know how to make a script to create a html page. So when the script is executed, it will create a new page. Something like this: mydomain.com/test.html . The script should create the test.html page!

嗯....我想知道如何创建一个脚本来创建一个html页面。因此,当脚本执行时,它将创建一个新页面。像这样:mydomain.com/test.html。该脚本应该创建test.html页面!

Here is my work:

这是我的工作:

<form action="index.php" method="post">
<input type="text" name="nick" value="Enter NIck" />
<input type="submit" value="Create" />
</form>

<?php

$nick=$_POST['nick'];      // get the users input

$fh=fopen('$nick' , 'W')    // Create the page
$contents= include 'sys.php';
fwrite($fh, $contents);
fclose($fh);

echo "Redridectring to your page....";

header('Location: $nick');

?>

Now, what this code should do is create a page, which is called $nick. So if the input is "bleugh", the $nick should be $nick="bleugh". Then it will create the page "bleugh", include sys.php, then header to the page. Is this wright? Will it work?

现在,这段代码应该做的是创建一个名为$ nick的页面。因此,如果输入是“蹩脚”,则$ nick应为$ nick =“bleugh”。然后它将创建页面“bleugh”,包括sys.php,然后标题到页面。这是怀疑吗?它会起作用吗?

3 个解决方案

#1


0  

You cannot use PHP variables that way inside single quotes

你不能在单引号内使用PHP变量

Is OK:

没关系:

"{$nick}"

Won't Work:

不会工作:

'$nick'

But am not sure what you're trying to do with "$contents= include 'sys.php';"? Perhaps you want to capture the output of sys.php into a string? Either way, you need to be careful with vulnerabilities you are opening yourself to.

但我不确定你要用“$ contents = include'sys.php';”来做什么?也许你想将sys.php的输出捕获到一个字符串中?无论哪种方式,您都需要小心自己打开的漏洞。

#2


0  

I think your method by creating a file and then redirect to the file is basically okay. Additional comments:

我认为通过创建文件然后重定向到文件的方法基本没问题。补充评论:

  1. Make sure the PHP process has write permission to the folder you write into.
  2. 确保PHP进程对您写入的文件夹具有写入权限。
  3. Do you really have to include sys.php? You need to write proper html tags into $contents when you really want to create a HTML file.
  4. 你真的必须包括sys.php吗?当您真的想要创建HTML文件时,需要在$ contents中编写正确的html标记。
  5. You should perform redirect before outputting any character, so your redirect would not work because it is preceded by an echo operation.
  6. 您应该在输出任何字符之前执行重定向,因此您的重定向将无法工作,因为它之前是一个echo操作。

#3


0  

try this

尝试这个

 header('Location: '.$nick.'');

#1


0  

You cannot use PHP variables that way inside single quotes

你不能在单引号内使用PHP变量

Is OK:

没关系:

"{$nick}"

Won't Work:

不会工作:

'$nick'

But am not sure what you're trying to do with "$contents= include 'sys.php';"? Perhaps you want to capture the output of sys.php into a string? Either way, you need to be careful with vulnerabilities you are opening yourself to.

但我不确定你要用“$ contents = include'sys.php';”来做什么?也许你想将sys.php的输出捕获到一个字符串中?无论哪种方式,您都需要小心自己打开的漏洞。

#2


0  

I think your method by creating a file and then redirect to the file is basically okay. Additional comments:

我认为通过创建文件然后重定向到文件的方法基本没问题。补充评论:

  1. Make sure the PHP process has write permission to the folder you write into.
  2. 确保PHP进程对您写入的文件夹具有写入权限。
  3. Do you really have to include sys.php? You need to write proper html tags into $contents when you really want to create a HTML file.
  4. 你真的必须包括sys.php吗?当您真的想要创建HTML文件时,需要在$ contents中编写正确的html标记。
  5. You should perform redirect before outputting any character, so your redirect would not work because it is preceded by an echo operation.
  6. 您应该在输出任何字符之前执行重定向,因此您的重定向将无法工作,因为它之前是一个echo操作。

#3


0  

try this

尝试这个

 header('Location: '.$nick.'');