有没有办法将值传递给另一个页面?

时间:2012-12-16 16:47:57

标签: php

我在a.php中的

$a = "hello,world";
$_POST['a'] = $a;
b.php

,我希望获得$a值,当我echo $_POST['a']时,没有值输出。我该怎么办?

4 个答案:

答案 0 :(得分:2)

您可以使用$_SESSION[]

以下是一个例子:

$_SESSION['a'] = $a;

并在a.php

中使用它

答案 1 :(得分:2)

页面 a.php

<?php
session_start();
$a = "hello,world";
$_SESSION["name_anything"] = $a; // This will store $a value to the session
//here i've given session name "name_anything"
?>

页面 b.php

<?php
session_start(); //you need to initiate the session using this function
//You need to session_start() on every page on which you want to use session.
//Even on the page on which you are storing the session.
echo $_SESSION["name_anything"]; //this will print the value of $a
?>

答案 2 :(得分:1)

这不是您将信息发布到其他页面的方式,您需要使用表单,或者另一种方法是使用GET请求,或者使用会话。

尝试阅读本文或其他php文章。 http://mrarrowhead.com/index.php?page=php_passing_variables.php

答案 3 :(得分:1)

这将是a.php中的HTML表单:

<form action="b.php" method="post" >
<input type="text" name="poster" />
<input type="submit" name="submit" />
</form>

在b.php中,你可以放一些PHP来回显数据

<?php

if(isset($_POST['submit'])){

echo $_POST['poster']; 


}