在php中重定向时如何将变量从一页传递到下一页?

时间:2018-06-25 16:01:49

标签: php arrays variables session logout

//第1页test.html

<form method = 'POST' action = 'test2.php'>
   <input type = "text" name = "ione"/>
   <input type = "password" name = "itwo"/>
   <input type = 'submit' value = 'Count'/>
</form>

//第2页-test2.php

    <?php
  $ione = $_POST ['ione'];
  $itwo = $_POST ['itwo'];
  if ($ione and $itwo != '')
  {
    echo "<form method = 'post' action = 'test3.php'>
    <input type = 'hidden' value= '$ione' name = 'ione' />
    <input type = 'hidden' value= '$itwo' name = 'itwo' />
    <input type = 'submit' />";
    header('location: test3.php'); die;
    echo "</form>";
  }
 else 
 {
    header('location: test.html'); die; 
 }

//第3页--test3.php

  SESSION_START();
  $ione = $_POST ['ion'];
  $itwo = $_POST ['itwo'];
  $_SESSION ['ione'] =  $_POST ['ion'];
  $_SESSION ['itwo'] = $_POST ['itwo'];
  echo "$ione $two";
  echo "$_SESSION ['ione'] $_SESSION ['itwo']";

 if ($ione and $itwo != '')
 {
      header('location: test4.php'); die;
 }
 else
 {
    echo "log out failed";
 }

//第4页-test4.php

 SESSION_DESTROY();

1)我最终进入了test3.php,但是test2.php中if循环下的所有形式的变量都没有带到test3.php中。

2)对于$ _POST和$ _SESSION,我得到的是test3.php和array()中所有变量的未定义变量。

如何修复#2并在test3.php中使if循环正常工作?

我还要如何验证session_destroy是否适用于test4.php?

0 个答案:

没有答案