0

I have two forms that i get user input from. form one is "index.php" which goes to form two "select.php. i use "options.php" to display some content and i plan on using the user input in the displays. the problem i am facing is that even though i have session_start(); on all three pages none of my variables pass through. i have done a var_dump($_SESSION); and echo $_SESSION; i even used session_regenerate_id(TRUE);

index.php session variables

if(isset($_POST['login'])){
     $_SESSION['name'] =  $_POST['name'];
     $_SESSION['surname'] = $_POST['surname']; 
     $_SESSION['email'] = $_POST['email'];}

select.php session variables

if(isset($_POST['submit'])){
   $_SESSION['checkIn'] = $_POST['checkIn'];
   $_SESSION['checkOut'] = $_POST['checkOut'];
   $_SESSION['islandList'] = $_POST['islandList']; 
 }

Below are the 3 headers of each page

<?php 
//index.php page 1
session_start();  
?>
<?php 
   if(!isset($_POST['name'], $_POST['surname'], $_POST['email'])){?>
// basic html form goes here.
<?php }
if(isset($_POST['login'])){
   $_SESSION['name'] =  $_POST['name'];
   $_SESSION['surname'] = $_POST['surname']; 
   $_SESSION['email'] = $_POST['email'];}
?>

<?php
//select.php    page 2
    session_start();
    echo $_SESSION['name']; // session variable does not go through
    echo $_SESSION['surname']; // session variable does not go through
    echo $_SESSION['email']; // session variable does not go through
?>



<?php
            if(isset($_POST['submit'])){
                $_SESSION['checkIn'] = $_POST['checkIn'];
                $_SESSION['checkOut'] = $_POST['checkOut'];
                $_SESSION['islandList'] = $_POST['islandList']; 
            }
            var_dump($_SESSION);
        ?> 

<?php 
// options.php  page 3
  session_start();
  require_once 'rateCalc.php';
?>


<?php 


echo $_SESSION; // session variables do not go through
var_dump($_SESSION); // session variables do not go through

?>

I am still very new to this. but from everything i have looked at i havent been able to see where i made a mistake. this happens across all 3 browsers. firefox, chrome and microsoft edge. i have checked cookies, checked session ids and it still wont work. another thing is, when i try use for example echo $_SESSION['islandList'] the variables wont pulkl through but if i use $_POST['islandList'] it sometimes works and from my lessons and notes i am under the impression that it is not supposed to worklike that in this instance. i havent managed to find a solution online. gone through about 20 sites via google.

PHP SESSION INFO

  • Check your PHP error log for "Headers already sent" warnings. That can interfere with sending the session cookie. – Barmar Jun 22 '21 at 19:05
  • Hi Barmar, I have edited the post with an insert of an image of my session information. i cannot seem to find the error log section –  Jun 23 '21 at 08:20
  • Why would you expect to find the error logging settings in the session settings? See https://stackoverflow.com/questions/5127838/where-does-php-store-the-error-log-php5-apache-fastcgi-cpanel – Barmar Jun 23 '21 at 14:07
  • _“I have two forms that i get user input from. form one is "index.php" which goes to form two "select.php.”_ - okay, and what is actually sending POST data _to_ the index.php in this scenario then? You did check `isset($_POST['login'])` in there and then tried to assign session variables from $_POST … but if you never actually submitted any form _to_ the index.php, then of course this won’t work. – CBroe Jun 25 '21 at 13:01

1 Answers1

0

Managed to solve it. Complete over kill but it does not work any other way.

    if(isset($_POST['login'])){
    $name = $_POST['name'];
    $surname = $_POST['surname'];
    $email = $_POST['email'];

    $_SESSION['name'] =  $name;
    $_SESSION['surname'] = $surname; 
    $_SESSION['email'] = $email;

      // delete 3rd ones
    $_SESSION['name'] =  $_POST['name'];
    $_SESSION['surname'] = $_POST['surname']; 
    $_SESSION['email'] = $_POST['email'];
  }
  if(isset($_POST['submit'])){
    $checkIn = $_POST['checkIn'];
    $checkOut = $_POST['checkOut'];
    $islandList = $_POST['islandList'];

    $_SESSION['checkIn'] = $checkIn;
    $_SESSION['checkOut'] = $checkOut;
    $_SESSION['islandList'] = $islandList;

    $_SESSION['checkIn'] = $_POST['checkIn'];
    $_SESSION['checkOut'] = $_POST['checkOut'];
    $_SESSION['islandList'] = $_POST['islandList'];
      
  }