This is content of in.header.php

if(!isset($session_id) || empty($session_id)) {
session_start();
$_SESSION["Inputs"]=array();
}

This is index.php which also has form objects that POSTs other values to step1.php

require_once 'inc.header.php'
$_SESSION["Inputs"]["name"]="MyName";
$_SESSION["Inputs"]["surname"]="MySurname";

This is step1.php

require_once 'inc.header.php'
$_SESSION["Inputs"]["age"]=$_POST["textboxAge"];
print_r($_SESSION["Inputs"]);

Problem is print_r prints only Array () . I cannot see name, surname and age.

What do i miss?

Thanks in advance

Hi,

If you haven't already read the function description for session_start(), read it here.

You have to call session_start at the beginning of every new page to continue the previous session. You may also find it beneficial to use session_name.

Check out the examples on the link I included.

R.

Member Avatar for diafol
if(!isset($session_id) || empty($session_id)) {
session_start();
$_SESSION["Inputs"]=array();
}

It's not clear where $session_id is declared if at all, therefore the code will always run regardless of whether you have a $_SESSION variable. In addition, $_SESSION["Inputs"]=array(); may overwrite previous $_SESSION variables, leaving you with an empty array.

Solved.
inc.header.php

<?php
session_start();
?>

index.php

<?php
require_once 'inc.header.php';
$_SESSION["Inputs"]["name"]="MyName";
$_SESSION["Inputs"]["surname"]="MySurname";

echo "<pre>";
print_r($_SESSION["Inputs"]);
?>

<form action="next.php" method="post">
<input type="textbox" name="age" value="15" />
<input type="submit" name="submit" value="send" />
</form>

next.php

<?php
require_once 'inc.header.php';
$_SESSION["Inputs"]["age"]=$_POST["age"];;

echo "<pre>";
print_r($_SESSION["Inputs"]);
?>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.