我在这里遇到了我的代码问题。我想要做的是在用户注册时自动在用户的文件夹中创建一个index.php文件。这实际上已经完成了,现在主要的问题是如何在创建的'index.php'文件中插入一行代码。下面的代码行我试图使用来执行:如何将一行php代码插入文本文件
这不工作(其实我是想什么):
$filePath = $_SERVER['DOCUMENT_ROOT']."/".$_SESSION['username']."/index.php";
$fp = fopen($filePath, 'wb')
or die("can't open file");
$content = "<?php require($_SERVER['DOCUMENT_ROOT']."/home.php"); ?>";
fwrite($fp,$content);
fclose($fp);
虽然这确实:
$filePath = $_SERVER['DOCUMENT_ROOT']."/".$_SESSION['username']."/index.php";
$fp = fopen($filePath, 'wb')
or die("can't open file");
$content = "this is a string";
fwrite($fp,$content);
fclose($fp);
所以我想要的是内容变量中的代码进入'index.php'文件。任何帮助如何做到这一点?
你得到的错误是什么?什么是输出到index.php文件? –
谢谢你的帮助!它已被修复 – Skeellz