PHP会话及其在互连页面中的使用也是页面重定向

时间:2017-07-27 06:10:03

标签: php forms session redirect

我有一个问题。 这是问题的范围:

在php上准备一份注册表格,在提交数据时,它将转到下一页。链接到第三页,并使用会话在此页面上打印收集的数据。

我是新手,所以不确定如何继续,但我已准备好表格。它如下

      <!DOCTYPE HTML>  
       <html>
       <head>

      </head>
       <body> 
       <h2> Form  Example</h2>

       <form method="post" action="">  
      Name: <input type="text" name="name" value="">

       <br><br>
      Address: <input type="text" name="address" value="">

       <br><br>
       Comment: <textarea name="comment" rows="5" cols="40"></textarea>
      <br><br>
       Gender:
     <input type="radio" name="gender"  value="female">Female
     <input type="radio" name="gender"  value="male">Male

    <br><br>
    <input type="submit" name="submit" value="Submit">  
  </form>
     </body>
    </html>

请指导我如何继续进一步

1 个答案:

答案 0 :(得分:0)

使用会话变量。

 <!DOCTYPE HTML>  
   <html>
   <head>

  </head>
   <body> 
   <h2> Form  Example</h2>

   //add the redirect page
   <form method="post" action="redirect_page.php">  
  Name: <input type="text" name="name" value="">

   <br><br>
  Address: <input type="text" name="address" value="">

   <br><br>
   Comment: <textarea name="comment" rows="5" cols="40"></textarea>
  <br><br>
   Gender:
 <input type="radio" name="gender"  value="female">Female
 <input type="radio" name="gender"  value="male">Male

<br><br>
<input type="submit" name="submit" value="Submit">  
 </form>
 </body>
</html>

操作中的redirect_page.php应具有以下代码。

<?php session_start();

//submitted button created session variabale
if( $_SERVER['REQUEST_METHOD'] == 'POST' )
{
    $_SESSION['submit']['name'] = $_POST['name'];

    $_SESSION['submit']['comment'] = $_POST['comment'];

    $_SESSION['submit']['gender'] = $_POST['gender'];
}

foreach ($_SESSION['submit'] as $key => $value)
{
    echo $key. ' = ' .$value.'</br>';
}
?>

//third Page Link
<a href ="thirdpage.php">Third Page</a>

名为thirdpage.php的第三个页面只需要有深浅的代码。因为redirect_page.php为我们创建了会话提交已经存在!

 <?php session_start();
    foreach ($_SESSION['submit'] as $key => $value)
    {
       echo $key. ' = ' .$value.'</br>';
    }
 ?>