0

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

3
Contributors
3
Replies
4
Views
8 Years
Discussion Span
Last Post by veledrom
0

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.

0
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.

0

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"]);
?>
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.