a.php
私は:
$a = "hello,world";
$_POST['a'] = $a;
で、値b.php
を取得したいのですが、 iの場合、値の出力はありません。私はどのように行いますか?$a
echo $_POST['a']
a.php
私は:
$a = "hello,world";
$_POST['a'] = $a;
で、値b.php
を取得したいのですが、 iの場合、値の出力はありません。私はどのように行いますか?$a
echo $_POST['a']
使用できます$_SESSION[]
。
次に例を示します。
$_SESSION['a'] = $a;
そしてそれを使用しますa.php
ページ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
?>
これは、別のページに情報を投稿する方法ではありません。そのためにはフォームを使用する必要があります。別の方法として、GET リクエストを使用するか、セッションを使用することもできます。
これ、または他のphp記事を読んでみてください。 http://mrarrowhead.com/index.php?page=php_passing_variables.php
これは、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'];
}