473,322 Members | 1,736 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Why is PHPSESSID cookie not setting?

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
0 1415

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

Similar topics

1
by: AmigaLemming | last post by:
As I understand my admins installed a PHP server and now my plain HTML pages also want to set a PHPSESSID cookie when loaded into a browser. Can I suppress this, e.g. by creating a configuration...
16
by: Jochen Daum | last post by:
Hi! I have a function in a lot of pages, which redirects to a new page, if a form has been submitted: if (!(defined("DEBUG_INSERT") && DEBUG_INSERT) && !(defined("DEBUG_UPDATE") &&...
2
by: Bill Seitz | last post by:
I'm trying to set a cookie to apply over all hosts in my domain. I have a settings file setting $domain ="quietcare.info"; $cookieDomain = ".".$domain; Then I use that $cookieDomain as an...
7
by: FamB | last post by:
I have the following code: $expireTime = 60*60*24*364; // 365 days session_set_cookie_params($expireTime); // seconds session_start(); My problem is, that my PHPSESSID expires before my...
1
by: Timur Tabi | last post by:
I have an embedded system with a web interface. One of the web pages has a small JavaScript program that, when run on IE6, always displays the message that cookies need to be enabled: if...
4
by: octavio.filipe | last post by:
Hi, I'm trying to use the following code: HttpWebRequest webRequest = WebRequest.Create(LOGIN_URL) as HttpWebRequest; webRequest.CookieContainer = new CookieContainer(); HttpWebResponse...
6
by: Harry Whitehouse | last post by:
I've got a fairly simple forms authentication project (a login page and a single secure page), but a number of users (~25%) can't seem to get past the login.aspx step. I theorized that this might...
5
by: Alan Silver | last post by:
Hello, I've just spent ages debugging some cookie code that wasn't working, and have finally discovered that the code *was* working, but that the path used by cookies is case-sensitive. I was...
1
by: zorro | last post by:
Greetings, I want users to select the duration time of their sessions. I'm able to do it by setting the PHPSESSID cookie duration. Is this reliable, or is it not recommended for some reason? ...
1
by: Todd Brewer | last post by:
I have an ASP.NET 2.0 site that stores a cookie on the browser. Instead of the domain name (www.somename.com) it comes accross as the IP address of the server. This works in Firefox, but fails...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.