Click to See Complete Forum and Search --> : [RESOLVED] Firefox 3 Cookie/Session Trouble


Joseph Witchard
09-10-2008, 12:16 AM
Is anyone else having trouble with cookies/sessions in Firefox? I thought it was just version three, so I put version two back on my system. But it's messing up too:confused:

NogDog
09-10-2008, 01:37 AM
What kind of trouble?

What are your Firefox privacy/security settings?

Joseph Witchard
09-10-2008, 01:52 AM
I switched back to Firefox 2 to see if that would fix it, but no, it's still happening. Anyway, my settings:

Privacy:
Everything is checked
Keep Until: They Expire

Security:
Checked:
Warn Me When Sites Try to Install Add-Ons
Remember passwords for sites

NOT Checked:
Warn me if this site is suspected of forgery
Use a master password

The trouble is my login script. It works perfectly in Internet Explorer (shocking, isn't it?), but in Firefox and Opera (dunno if the problem is related), the session information doesn't get carried over to the admin page when you're redirected, so you always get sent to the permission error page. I've looked it up, and a lot of people are having different cookie trouble with Firefox 3 (hence why I posted this thread with the above title), but I switched back to Firefox 2, and it does the same thing.

Fang
09-10-2008, 02:39 AM
Have you set the path to root?

Having Fx3 and Fx2 on the same PC can cause problems as they use different profile constructions.

Joseph Witchard
09-10-2008, 02:44 AM
How do I do that?

Having Fx3 and Fx2 on the same PC can cause problems as they use different profile constructions.

No worries there. I uninstalled FF3 from my computer before I installed FF2.

Fang
09-10-2008, 03:12 AM
http://www.quirksmode.org/js/cookies.html#link5

Did the uninstall remove the profile?

Joseph Witchard
09-10-2008, 01:04 PM
I'm not sure if it did or not. I might try that again.

And the path is already set as "/". So it should be working, shouldn't it?

Fang
09-10-2008, 01:37 PM
Can you read the cookie on the second page at all.
Can we see the cookie scripts?

Joseph Witchard
09-10-2008, 01:52 PM
Login page:
<?php

// start the session

session_name('pickles');
session_set_cookie_params(900);
session_start();


// include the connection settings



define('DB_HOST', 'host');
define('DB_USER', 'user);
define('DB_PWD', 'password');
define('DB_NAME', 'database');

// connect to the database

$conn = new mysqli(DB_HOST, DB_USER, DB_PWD, DB_NAME);

// process the form

if (array_key_exists('login', $_POST) && ! empty($_POST['login']))
{
// create an empty array for missing fields

$missing = array ();

/* here, I'm going to create an
array to hold the form fields.
if the form fields are empty,
I'll add them to the $missing
array. */
$fields = array ("F_Username"=>$_POST['username'], "F_Pwd"=>$_POST['pwd']);
foreach ($fields as $field=>$value)
{
if (empty($field))
{
array_push($missing, $field);
}

}

// if $missing is empty, continue the processing
if (empty($missing))
{
// assign the form fields to variables
$username = $fields["F_Username"];
$pwd = $fields["F_Pwd"];

$query = "SELECT user_id, username FROM users WHERE username= ? AND pwd = ? LIMIT 1";

// prepare the statement
if ($stmt = $conn->prepare($query))
{
// bind the parameters
$stmt->bind_param('is', $username, $pwd);

// execute
if ($stmt->execute())
{
$stmt->bind_result($id, $username);
if ($stmt->fetch())
{

$_SESSION['news'] = true;
$_SESSION['id'] = $id;
$_SESSION['username'] = $username;

$stmt->close();



header("Location: http://www.uhrebirth.com/staff/admin_center.php");

exit;
}

}
}
}
}

?>


Member area:
<?php // check to see if the session is set


session_name('pickles');
session_set_cookie_params(900);
session_start();

if (empty($_SESSION['news']) || $_SESSION['news'] != true) {

// send them to the error page
header("Location: http://www.uhrebirth.com/test/permission_error.php");

exit;

}
else
{

include("admin_logout.php");


}




?>

And here is what I get when I select Show Cookies from my Firefox options:

Name: pickles
Content: 6pr0pr87dkeppjnpqeskaum4i5
Host: uhrebirth.com
Path: /
Send For: Any type of connection
Expires: Wednesday, September 10, 2008 12:59:11 PM

Name: pickles
Content: 40susb9e6pl53vohqg1jm0gcr7
Host: www.uhrebirth.com
Path: /
Send For: Any type of connection
Expires: Wednesday, September 10, 2008 12:59:27 PM

NogDog
09-11-2008, 12:53 AM
You are getting different domain names (one with a "www" subdomain, one without). You are probably accessing the page via "http://uhrebirth.com/", but the the location header() call is going to "http://www.uhrebirth.com/". You could add the following to your session cookie params:

session_set_cookie_params(900, '/', '.uhrebirth.com'); // note leading "."

Joseph Witchard
09-11-2008, 01:02 AM
I had no idea that would affect it:confused: I made some appropriate changes and it worked. Thanks everyone:D

cemm
10-13-2008, 01:13 PM
i have the same problem..
could u tell me about the changes you did? or could u tell me what kind of changes i must do with the code at below?

i am makeing the login progress like this:

if (substr_count ($_SERVER['HTTP_HOST'], ".") == 1)
{$cookie_domain = "." . $_SERVER['HTTP_HOST'];}
else{$cookie_domain = preg_replace ('/^([^.])*/i', null, $_SERVER['HTTP_HOST']);}

ini_set ("session.cookie_domain", $cookie_domain);
ini_set("session.cookie_path", "/");
session_start();
session_register("uname");
session_register("upass");

I had no idea that would affect it:confused: I made some appropriate changes and it worked. Thanks everyone:D

Joseph Witchard
10-23-2008, 01:20 AM
Well, I was accessing my login page via the https protocol. However, in the redirect, I was sending the user to a page using http. So, PHP thought it was leaving the page, and therefore the session was getting unset.

I apologize, but I'm nowhere near skilled enough to answer your question:o If you post it in the PHP forum, I'm sure some of the veterans of this forum (NogDog, SyCo, etc.) would be able to assist you better.