我卡在这里了,代码正常工作但无法将变量保存到新创建的'sample.php'文件中。
<?php
$id = 3;
$name = "John Smith";
$myfile = fopen("sample.php", "w") or die("Unable to open file!");
$txt = "
<?php
// Start the session
session_start();
// Set session variables
$_SESSION[\"user\"] = $id; // integer variable
$_SESSION[\"name\"] = \"$name\"; // string variable
header('Location: home/start.php');
?>
";
fwrite($myfile, $txt);
fclose($myfile);
?>