用于重定向页面的PHP Session变量

时间:2018-05-21 14:17:55

标签: php

我有几个带有用户表单的html页面,并在其上应用PHP来读取和写入文本文件上的数据。我想根据当前页面上的会话变量来重定向到下一个html页面,但不知道如何实现它。

HTML 1:

<div class="enterUserId">
      <h4>Please enter your user ID:</h4>
      <form method="post" action="processUserID.php">
        <input type="text" name="userID" required>
        <input type="submit" value="Submit" id="intro">
      </form>
</div>

HTML 2:

<form method="post" action="processUserID.php">
  <select name="rank1" id="select1" size="1" style="width:80px;" required >
                    <option value="" selected="selected" disabled hidden>Rank</option>
                    <option value="1">1</option>
                    <option value="2">2</option>
                    <option value="3">3</option>
                    <option value="4">4</option>
                    <option value="5">5</option>
                    <option value="6">6</option>
                  </select>

<input type="submit" value="Proceed" name="submit" id="submit" />
    </form>

PHP:

<?php

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

      $myfile = fopen("temp/userID.txt", "w");
      $userID = $_POST['userID'].";\n";
      for ($i = 0; $i <= 5; $i++) {
        fwrite($myfile, $userID);
      }
      //what potentionally needs to be handled by session variables
      header("Location: main.html");
    }


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

      $ranks = fopen("temp/ranks.txt", "w");
      $selected_val = $_POST['rank1'].";\n".$_POST['rank2'].";\n".$_POST['rank3'].";\n".$_POST['rank4'].";\n".$_POST['rank5'].";\n".$_POST['rank6'].";";
      fwrite($ranks, $selected_val);
      header("Location: main2.html");
      }

&GT;

所以,我需要包含这样的内容来替换导航但不确定如何实现它:

session_start();

   if (isset($_SESSION['counter'])) {
      $_SESSION['counter'] = 1;
   }else {
      $_SESSION['counter']++;
   }

提前谢谢!

0 个答案:

没有答案