Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

IM LOSING MY VARIABLES...

Status
Not open for further replies.

aarrgghh

Technical User
Sep 5, 2002
60
US
... and my marbles. I am transfering session variable from page to page, well, at least I'm trying to. I am having users go through a web site in a very structured way. That is, the site has a beginning and an end. As a result, I need to keep track of the users current location and the farthest point attained in the site. The current point and farthest point attained will control the activation and deactivation of links to other sections within the site. Now I can pass the $_SESSION['variables'] to the first page, but after that the variables are lost. Here is what I have:
-----------------------------LogInProcess.php--------------
/*Processes the login information that is received from the login page */


<?php
session_start();
$register = session_register(&quot;firstName&quot;, &quot;lastName&quot;, &quot;currentPage&quot;, &quot;lastPage&quot;);


$firstName = $_POST['firstName'];
$lastName = $_POST['lastName'];
$currentPage = $_POST['currentPage'];
$lastPage = $_POST['lastPage'];

if (!$register)
{echo &quot;Cannot register session variables<br>&quot;;}
else {echo &quot;Registered session variables<br>&quot;;}

// omitted code that writes to a database

LINK TO FIRST PAGE

-----------------------intro.php---------------------------
<?php
session_start();
$_SESSION['currentPage'] = 0;

/*Checks to make sure that the current page is not farther then the farthest page reached*/

if ($_SESSION['currentPage'] > $_SESSION['lastPage'])
{$_SESSION['currentPage'] = $_SESSION['lastPage'];}

$registered = session_is_registered('firstName');

if ($registered)
{echo &quot;Variables<br>&quot;.$_SESSION['firstName']. &quot;<br>&quot;
.$_SESSION['lastName']. &quot;<br>&quot;
.$_SESSION['currentPage'].&quot;<br>&quot;
.$_SESSION['lastPage'].&quot;<br>&quot;;
}

else{echo &quot;Lost the variable&quot;;}

?>

/* NOW THIS PRINTS ALL THE RIGHT CONTENTS I.E.
Variables
users firstName
users lastName
currentPage
lastPage */

LINK TO NEXT PAGE
------------------------next.php---------------------------

<?php
session_start();
$_SESSION['currentPage'] = 1;

/*Checks to make sure that the current page is not farther then the farthest page reached*/

if ($_SESSION['currentPage'] > $_SESSION['lastPage'])
{$_SESSION['currentPage'] = $_SESSION['lastPage'];}

$registered = session_is_registered('firstName');

if ($registered)
{echo &quot;Variables<br>&quot;.$_SESSION['firstName']. &quot;<br>&quot;
.$_SESSION['lastName']. &quot;<br>&quot;
.$_SESSION['currentPage'].&quot;<br>&quot;
.$_SESSION['lastPage'].&quot;<br>&quot;;
}

else{echo &quot;Lost the variable&quot;;}

?>

/* NOW THIS ONLY PRINTS the word &quot;Variables&quot;. This tells me that the session is registered, but somehow not visible?*/



Any ideas? Also keep in mind that I am currently just trying to be successfull accessing and passing $_SESSION['variables'] before I actually use them in the site. This is why I want to print out the variables on each page.
 
Inspect what the $_SESSION superglobal array contains:
Code:
print_r($_SESSION);

Go from there.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top