PHP Session Variables not staying set on next page

Hi,

I have a PHP script that I use every year around this time.  Last year it worked fine, this year it doesn't.  I wondered if anyone could see what I'm missing...

I have a login script that users type their username/password in.  Once the info is verified via MySQL I move on to the next page using this code:

                  $userid = $row["ID"];
                              
                  //Set cookie and seesion info
                  setcookie("admin", "loggedin", time()+3600);
                  setcookie("userid", "$userid", time()+3600);
                  $_SESSION["userid"] = $userid;
                  //echo $_SESSION["userid"];
                  header("Location: Grid.php");
                  exit();

When I test it by printing the userid is it being set. (i.e. 20 will print on the screen).

When I move on to the next page, the $_Session variable is no longer set.  The first few lines of Grid.php are:

<?
      //Security
      session_start();
      echo "USER:".$_SESSION["userid"];

At this point the $_Session variable is blank and that's what prints on the screen (nothing).

Has something changed about Sessions or is there something I'm missing.  I use a web host so I don't have a lot of control over PHP.  Any help would be appreciated!
LVL 2
jfrentAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

hernst42Commented:
I don't see a session_start() on the page where you do the check:

 //Set cookie and seesion info
                  setcookie("admin", "loggedin", time()+3600);
                  setcookie("userid", "$userid", time()+3600);

That might be a reason why $_SESSION does not contain the info set on the check page.
0
LotokCommented:
Yup, its always handy to have session_start() in your config.php which gets included on each page.
0
jfrentAuthor Commented:
Thanks guys.  The session start is included in the beginning of the login.php page (1st code snip).  That was the first thing I checked, sorry I should've mentioned that.
0
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

hernst42Commented:
Does the following script works on your server? The value outputed should increase with each pageload.
<?php
 
session_start();
if (!isset($_SESSION['testnum'])) {
   $_SESSION['testnum'] = 1;
} else {
   ++$_SESSION['testnum'];
}
 
echo $_SESSION['testnum'];

Open in new window

0
LotokCommented:
I am guessing your login page uses a form, you post the data to formname.php and then from there it redirects to the relevant page depending on the success of the credentials.


This would mean you have 3 pages, the login page, the post form and then the outcome page. Do all 3 have the sessionstart?

Are you running the script on the same server? Is sessions enabled in phpconfig?
0
jfrentAuthor Commented:
Thanks for the suggestions.  I don't think the code above is complete (only 10 lines can be copied).

The form is directed to itself so there are only the two pages.  My web host may have changed servers, I'm not sure.  And I don't know if I have access to the phpconfig file.  I'll need to check on that.

It sounds like the Sessions may be turned off though...
0
hernst42Commented:
The code is complete if you create a page test.php with that code and call the page multiple times and the counter does not increase the session management on the server is broken.

Demonstration:
http://ee.jojo.is-a-geek.net/~hernst/ee/23116055.php
0
jfrentAuthor Commented:
Thanks hernst42.  After I wrote the note, I actually checked it and saw that the only thing missing was the closing ?>

Sorry to imply that you didn't give the complete code!

I check it and on my server the number does not increment.  It stays on 1.  Which proves that something is going on...

Still checking on the PHPConfig file...
0
hernst42Commented:
Are you sure you haven't blocked cookies from the domain your are testing the sessions on? Else the errorlog should indicate what's going wrong with the php-installation
0
jfrentAuthor Commented:
I see my web host gives me access to a PHP.ini file.  Is that the same thing?  It appears that Sessions are turned on.

I forgot to mention that another check I did early on was to use the session_name() function to return the session name.  It was the same on both pages (PHPSESSID) and matches what is listed in the PHP.ini file.

Does that provide any proof that Sessions are turned on?
0
jfrentAuthor Commented:
I use both the Session variable and cookies for this script.  The cookies are working as expected.  I have double-checked no cookie blockage.
0
hernst42Commented:
Then check the error-log of the webserver, maybe a disk is full or something else happens with the session-data-file
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jfrentAuthor Commented:
Upon reviewing the error logs for the server I found that the variable 'session.save_path' in the PHP.ini file was pointing to a directory that didn't exist.  Changing the directory fixed everything.  Thanks for your help!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.