1

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

22
  • 2
    First try to not put the $_SESSION["auth"] in the echo. The quotes will throw it off. Instead do this... echo 'auth = '.$_SESSION["auth"].' <br />"; Commented Aug 20, 2013 at 1:10
  • Additionally to @CP510 comment, are you sure the code is executed properly and that the $_SESSION["auth"] is actually lost? Check it using the isset function: if(isset($_SESSION["auth"] )){echo "Session Auth is set";} Commented Aug 20, 2013 at 1:14
  • @CP510 ok changed it. still same result. Commented Aug 20, 2013 at 1:14
  • Try doing this echo "$auth = ".$_SESSION["auth"]."<BR />"; adding a $ to auth. auth should be a variable. Am just not sure what it is you are trying to achieve. Commented Aug 20, 2013 at 1:16
  • @NickL. Yes it is definitely lost. I just added your code, same result. Commented Aug 20, 2013 at 1:16

2 Answers 2

3

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:

  1. 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);
  2. 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);
  3. You can check your PHP config file (php.ini) to make sure that there are no settings causing session issues directly.
Sign up to request clarification or add additional context in comments.

1 Comment

/var was full because of an out of control mail program. The error reporting made that come up and was easy to see. Thanks!!!
1

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 />";
?>

4 Comments

You shouldn't write echo "auth = {$_SESSION["auth"] } <BR />"; like that, as the double quoutes around the auth key will throw it off. At best, it should be: echo "auth = {$_SESSION['auth'] } <BR />"; or echo 'auth = {'.$_SESSION["auth"].' } <BR />';
@MSost, the double quotes do work (if you try it, you'll see it functions fine), as PHP enters a new parsing mode when it reaches {$...} (complex syntax), but it might not be the best for readability: php.net/manual/en/language.types.string.php
@Adam That's for the info, agreed on readability, but if it works I retract my statement :) I've just never thought that would work/to do that!
@RichardDesLonde Actually Richard, I got the exact same results (from accepted answer) with or without the space before the curly brace, using FF v23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.