Question

I have been working on writing a program and the session ID's have been working for several days. Now all of a sudden they are not working anymore. Any advice? The script codes are below for the test script I wrote to test passing the session ID's.

This is how I have the login page started, with no line breaks before this code.

<?php session_start();
?>
<!--HTML HEADER-->
<form action="sessionID.php" method="post">
name: <input name="stName" type="text" /><br/>
pass: <input name="newPass" type="text" /><br/>
<input name="" type="submit" value="submit"/>
</form>

It is passed through another page to test passing through a HREF link. Here is the top of that script.

<?php session_start();
$_SESSION['student']=$_POST['stName'];

Final page to echo the session ID.

<?php session_start();
$student = $_SESSION['student'];
echo session_id();

Anything I am doing wrong...?

Was it helpful?

Solution 3

When I redirected after verifying username password, I used http://www.domainname. I switched the redirect to http://domainname (no www.) and $_SESSION['user'] works perfect.

OTHER TIPS

You saved your value to $_SESSION['student']

Use:

<?php session_start();

$student = $_SESSION['student'];

//echo session_id(); 

echo $student;

?>

Echoing session_id(); will echo a series of number/letters, and not the actual name.

In order to echo the (student) name of the input given from a form is:

echo $_SESSION['student'];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top