'Having problems with sessions not allowing flow from isset to isset in same page
I have a page titled "test.php"
When I remove all session statements it works fine. However I wish to create session for security purposes (cannot get in without verification).
After the user enters username and password they are taken to the verify section where they click on "Continue". This then goes to a list of tests that they can select to take. But when they click on the test, only the template is displayed and no data. If I remove session info, everything works well.
Would appreciate assistance Phil
<?php
session_start();
?>
some basic html here (title metadate etc. nothing pertinent to the workings of this page)
<?php
// ========================================= session
if(isset($_SESSION['stud_id'])) {
$student=$_SESSION["student"] ;
$stud_id=$_SESSION["stud_id"] ;
// ========================================= login screen
if(!isset($_POST['logged']) ) {
$page_content ="log in screen
";
} // close isset login screen
// ========================================= verify password and username
if(isset($_POST['verify']) ) {
$page_content ="Welcome and continue screen ==> goes to test list
";
} // close isset verify username and psw
// ========================================= test list
if(isset($_POST['list']) ) {
$page_content =" Presents test areas ==> on selection goes to test questions
";
} // close isset list questions
========================================= take test
if(isset($_POST['questions']) ) {
$page_content =" answer questions and ==> goes to score
";
} // close isset questions
// ========================================= scoring
if(isset($_POST['score']) ) {
$page_content =" scores test, updates student record === this is the end of the test === process
";
} // close isset score
// ========================================= clsose session
} // close if session
// remove all session variables
session_unset();
// destroy the session
session_destroy();
?>
</head>
<body>
<?php
$content = $page_content;
include('template.php'); ======= template for standard look page =========
?>
</body>
</html>
Solution 1:[1]
What I was attempting to do was to have a login along with an online test. In retrospect, I created a separate login page that created $_SESSION["stud_id"] = $student_id; $_SESSION["student"] = "$student";
On the test page "if(isset($_SESSION['stud_id'])) {" and its corresponding closing bracket were removed and an if exist id and name code inserted as a form of verifying the student login.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Phil R |