By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,965 Members | 2,043 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,965 IT Pros & Developers. It's quick & easy.

Why is PHPSESSID cookie not setting?

P: 75
Hi,

I am trying to start a user session when a user logs in to my website. The setup is pretty simple. Here is my checkLogin.php script that checks whether the user is a member of the website.
Expand|Select|Wrap|Line Numbers
  1. <?
  2.   session_start();
  3.   $username = $_POST["username"];
  4.   $password = $_POST["password"];
  5.  
  6.   include '../connect.php';
  7.  
  8.   $sql = sprintf( "SELECT * FROM members WHERE username = '%s' AND password = '%s'", $username, $password );
  9.   $res = mysql_query( $sql );
  10.  
  11.   $count = mysql_num_rows( $res );
  12.   if ( $count == 1 ){
  13.     $_SESSION["username"] = $username;
  14.     $_SESSION["loggedIn"] = true;
  15.     header( "Location:/pro/" );
  16.   } else {
  17.     header("Location:/");
  18.   }
  19. ?>
  20.  
I then direct the player to the /pro/ section of the website which has an equally simple setup, while checking to ensure that the user is actually logged in with the session.
Expand|Select|Wrap|Line Numbers
  1. <?
  2.   session_start();
  3.   if (!$_SESSION['loggedIn']){
  4.     header("Location:/");
  5.   } else {
  6.   ?>
  7. <html>
  8. <body>
  9.   <?
  10.     $currentUser = $_SESSION['username'];
  11.     echo $currentUser;
  12.   }
  13.   ?>
  14.   <p>Welcome to the pro section.</p>
  15.   <a href="Logout.php">Logout</a>
  16. </body>
  17. </html>
  18.  
For some reason this does not work at all, and I'm clueless as to why. I also checked to see whether the PHPSESSID cookie was setting, but it does not appear to be the case. Here is an image from the Developer Tools in Chrome:


Ordinarily, there would be a request cookie with PHPSESSID as the name, but not with me. Is there something I need to configure in my php.ini file or is the code wrong?

I am baffled!

Any help would be appreciated!
Feb 23 '12 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.