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

richard
  • 12,263
  • 23
  • 95
  • 151
  • 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"].'
    ";`
    – CP510 Aug 20 '13 at 01: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";} – Nick Louloudakis Aug 20 '13 at 01:14
  • @CP510 ok changed it. still same result. – richard Aug 20 '13 at 01:14
  • Try doing this `echo "$auth = ".$_SESSION["auth"]."
    ";` adding a `$` to `auth`. `auth` should be a variable. Am just not sure what it is you are trying to achieve.
    – Funk Forty Niner Aug 20 '13 at 01:16
  • @NickL. Yes it is definitely lost. I just added your code, same result. – richard Aug 20 '13 at 01:16
  • @Fred-ii- Why should auth be a variable? – richard Aug 20 '13 at 01:17
  • Are sessions enabled on your servers configuration? Check with a nifty `phpinfo()` call – CP510 Aug 20 '13 at 01:17
  • If anything you probably should be doing this: `$auth = $_SESSION["auth"]; echo $auth;` – Funk Forty Niner Aug 20 '13 at 01:18
  • Wait a minute. Your login page never sets the auth variable in login.php, did you change the code? – CP510 Aug 20 '13 at 01:18
  • @RichardDesLonde Because you're including the `equal` sign and trying to assign something to it, unless that's your goal? To print that line? That's why I don't understand what you're trying achieve. – Funk Forty Niner Aug 20 '13 at 01:18
  • @CP510 That's what I've been trying say to the OP about `auth`. – Funk Forty Niner Aug 20 '13 at 01:19
  • @Fred-ii- It is not necessary to do that. You do not need to set a variable here. – CP510 Aug 20 '13 at 01:19
  • **OP CHECK YOUR SOURCE CODE** make sure there is something in login.php doing this... `$_SESSION['auth'] = "yes";` – CP510 Aug 20 '13 at 01:20
  • @CP510 Ok, I don't understand what the OP is trying to do. Looks to me it's just to echo out `auth = ".$_SESSION["auth"]."
    ` with a line break. *Confused and baffled*
    – Funk Forty Niner Aug 20 '13 at 01:21
  • @CP510 I edited this question and accidentally deleted the part where it sets the variable. I just fixed it in the question. It is reflecting correctly now what I have in my code. – richard Aug 20 '13 at 01:21
  • I just want to start a simple session, set a variable, and retrieve it on another page. It's not working. – richard Aug 20 '13 at 01:22
  • Thank you. Check that your sessions are enabled by creating a php page and adding `phpinfo()` to that. Thats the only line needed. Navigate to it and it will display your server settings. – CP510 Aug 20 '13 at 01:22
  • here is the phpinfo page...http://proserv01.services.lyris.com/NFPInsurance/UnsegmentedMemberReport/phpinfotest.php – richard Aug 20 '13 at 01:24
  • Check this one here: http://stackoverflow.com/questions/2542427/how-do-i-continue-a-session-from-one-page-to-another-with-php – Nick Louloudakis Aug 20 '13 at 01:35
  • @RichardDesLonde Sorry Richard, the only thing I can suggest and what I think what you're trying to do is to echo the session ID itself. Try `echo "portal page link. Auth set to: " .$_SESSION["auth"]. "";` (un-tested) see if that's your expected result. Other than that, I don't know what else to answer you with. – Funk Forty Niner Aug 20 '13 at 01:42
  • @RichardDesLonde My suggestion above will throw an error, I know, just tested it now. I tried using double quotes. Here's a working example `echo 'portal page link. Auth set to: " .$_SESSION["auth"]. "';` however I think it's a variation of what you already have. – Funk Forty Niner Aug 20 '13 at 01:46
  • @RichardDesLonde I have a question. Is `echo "auth = {$_SESSION["auth"] }
    ";` supposed to print/echo `auth = yes` ? Is that your expected result? Or as `href` => `portal page link. Auth set to: yes` ?
    – Funk Forty Niner Aug 20 '13 at 01:55

2 Answers2

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.
AdamJonR
  • 4,703
  • 2
  • 22
  • 24
  • 1
    /var was full because of an out of control mail program. The error reporting made that come up and was easy to see. Thanks!!! – richard Aug 20 '13 at 07:44
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 />";
?>
Community
  • 1
  • 1
Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
  • You shouldn't write `echo "auth = {$_SESSION["auth"] }
    ";` like that, as the double quoutes around the `auth` key will throw it off. At best, it should be: `echo "auth = {$_SESSION['auth'] }
    ";` or `echo 'auth = {'.$_SESSION["auth"].' }
    ';`
    – M Sost Aug 20 '13 at 02:35
  • @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: http://php.net/manual/en/language.types.string.php – AdamJonR Aug 20 '13 at 02:56
  • 1
    @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! – M Sost Aug 20 '13 at 03:01
  • @RichardDesLonde Actually Richard, I got the exact same results (from accepted answer) with or without the space before the curly brace, using FF v23 – Funk Forty Niner Aug 20 '13 at 15:14