如果是file_1.php
<?php
$_POST["test_message"] = "Hello, world";
header("Location: http://localhost/file_2.php");
?>
Run Code Online (Sandbox Code Playgroud)
这是file_2.php
<html>
<head>
</head>
<body>
<?php
if (!(isset($_POST["test_message"])))
echo "Test message is not set";
else
echo $_POST["test_message"];
?>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
输出是 Test message is not set
这让我想知道是否有人甚至可以写入$ _POST,并且想知道,我想知道这样做是不好的做法.我是否应该让提交按钮和方法的表单为我写邮件给$ _POST,或者写入$ _POST以在文件之间传递数据是否合法?
$_POST["test_message"]在file2.php中为空,因为您实际上没有向该脚本发布任何内容.该$_POST阵列由发布表单数据填充,你可以填充$_GET通过附加一个GET变量,以你的头重定向或存储数据$_SESSION,如果你需要的页面之间的数据持久性.
| 归档时间: |
|
| 查看次数: |
4668 次 |
| 最近记录: |