Link to home
Start Free TrialLog in
Avatar of carlbrooks1995
carlbrooks1995

asked on

Do I need to include something in the second php page

I have 3 php pages. In the first page I have this code below:


      $_SESSION['teacherforename'] = $dbTeacherForename;
      $_SESSION['teachersurname'] = $dbTeacherSurname;

Open in new window

In the second page I do not have any code posting or containing the session variable on ` $_SESSION['teacherforename']`, `$_SESSION['teachersurname']`.

In the third page I have this code below:

    if (isset($_POST['teacherforename'])) {
    
    $_SESSION['teacherforename'] = $_POST['teacherforename'];
    
    }
    
    if (isset($_POST['teachersurname'])) {
    
    $_SESSION['teachersurname'] = $_POST['teachersurname'];
    
    }

Open in new window


But what my question is that do I need to include something in my second page like a post or a session variable? In other words in the second page may I also have to include the same code I have in the third page?
Avatar of haloexpertsexchange
haloexpertsexchange
Flag of United States of America image

All you need on the third page is for the second page to post a form to page three with the information you need so that $_POST is available and for the session all you need is session_start(); at the beginning and you can use the session information provided page one and three come from the same domain.
Avatar of carlbrooks1995
carlbrooks1995

ASKER

@haloexpertsexchange You see the problem is that in the third page, I am using an ini_set() where it extends the session expiry time. The only problem is that out of all of the $_SESSION variables in the third page, only 2 session variables expire earlier than the allocated time and them 2 are:  
$_SESSION['teacherforename'] 

Open in new window

and
$_SESSION['teachersurname'] 

Open in new window

THe only reason that these 2 session variables are expiring is that the other session variables are posted from the 2nd page, while the 2 expiring session vairables are posted from the first page. Do I need to change my code a bit in third page or do I need to include something in 2nd page? I do have session_start(); in all the pages by the way.
ASKER CERTIFIED SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Dave Baldwin
Note that if you are using session_start(); properly, the session timer is reset every time you access one of the pages in the session.  That affects All of the $_SESSION variables.  They all expire when the session expires.