问题
Login page:
<?php
session_start();
#echo session_id ();
$_SESSION["auth"]= "yes";
echo '<a href="Portaltest.php?t='.time().'">portal page link. Auth set to: {$_SESSION["auth"]}</a>';
?>
Portal page:
<?php session_start();
echo "auth = {$_SESSION["auth"] } <BR />";
echo session_id ();
?>
The auth
session is lost between the two pages somehow!
Edit
Here is a test url:
http://proserv01.services.lyris.com/NFPInsurance/UnsegmentedMemberReport/logintest.php
回答1:
When trouble-shooting sessions, there are a few things I tend to do, but let's start with your code.
Here is an updated version of your page code so you actually see the value stored in $_SESSION['auth'] (your quotes were causing some trouble):
<?php
session_start();
$_SESSION["auth"] = "yes";
echo '<a href="Portaltest.php?t='.time().'">portal page link. Auth set to: ' . $_SESSION["auth"] . '</a>';
?>
Here is the updated version of the portal page, which removes the additional space after the closing curly bracket:
<?php
session_start();
echo "auth = {$_SESSION["auth"]} <BR />";
?>
Now, if you don't see the auth with these revisions, you can try:
- Changing the code in portal so it just dumps out the session so you can see what you've got: session_start(); var_dump($_SESSION);
- Checking to make sure the error reporting is enabled, as PHP helps you identify many potential issues quite quickly (e.g., index doesn't exist, the headers were already sent, etc.): ini_set('display_errors','1'); error_reporting(E_ALL);
- You can check your PHP config file (php.ini) to make sure that there are no settings causing session issues directly.
回答2:
NOTE: For testing purposes only.
I am unsure as to what the expected results are, yet I will submit this as an answer with explanations set inside PHP comments.
Give this a try:
<?php
session_start();
$_SESSION["auth"]= "yes";
// will echo: portal page link. Auth set to: yes
echo '<a href="Portaltest.php?t='.time().'">portal page link. Auth set to: ' . $_SESSION["auth"] . '</a>';
echo "<br>";
// will echo: auth = yes
echo "auth = {$_SESSION["auth"] } <BR />";
?>
来源:https://stackoverflow.com/questions/18325456/php-session-variables-not-saving-between-pages