• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 289
  • Last Modified:

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?
0
carlbrooks1995
Asked:
carlbrooks1995
1 Solution
 
haloexpertsexchangeCommented:
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.
0
 
carlbrooks1995Author Commented:
@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.
0
 
Ray PaseurCommented:
If I understand you correctly, I think the logic is backwards.  Try something more like this in page 3.
// IF THE SESSION HAS NO NAME, AND THE NAME IS IN POST, COPY THE NAME INTO THE SESSION 
if (!isset($_SESSION['teacherforename']))
{
    if (isset($_POST['teacherforename'])) 
    {
        $_SESSION['teacherforename'] = $_POST['teacherforename'];
    }
}

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

Open in new window

HTH, ~Ray
0
 
Dave BaldwinFixer of ProblemsCommented:
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.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now