|
Posted by Paul Duffy on 07/21/07 16:57
Not sure what's going on here or even if it /is/ a PHP problem but...
Using PHP 5.1.6 on a remote server, accessing the page locally and I have
certain preconditions for setting cookies, not setting cookies, updating
cookies, etc.
When accessed from Konqueror this all behaves as expected, when accessed
from Firefox however it all starts looking a bit weird.
The problem is that when the browser sends a cookie value that isn't stored
in the database (and, so far, when $_SESSION has /a/ cookie_id value),
while the desired result of a new db row and a reset cookie and session
value are achieved, the variables I'm using to trace what's happening
report values as though the cookie was always there.
Now, this _doesn't_ happen when I use Konqueror (I haven't yet tested
anything else) and everything happens as I expect it to. As it goes, if
you don't know how it's works when it's working, you won't know how to fix
it when it's broke so as much as it may all come to the same conclusion
I'd still like to know what's happening.
Output under FireFox with a new session after wiping the db clean is:
<!-- Initial cookieID = 118503664987 Initial Serv.cookieID = 118503664987 -->
<!-- COOKIE['ID'] 1 118503664987 -->
<!-- SESSION['cookieID'] 2 0 COOKIE['ID'] 3 0 -->
<!-- SESSION['cookieID'] 4 0 -->
<!-- SESSION['cookieID'] 5 118503664987 COOKIE['ID'] 6 118503664987 -->
<!-- Stored Cookie is 1 -->
<!-- SESSION['cookieID'] 7 0 -->
<!-- cookieTime -->
<!-- cookieRand -->
Output under Konqueror (hoped for output) is:
<!-- Initial cookieID = 118488413231 Initial Serv.cookieID = -->
<!-- COOKIE['ID'] 1 118488413231 -->
<!-- SESSION['cookieID'] 2 0 COOKIE['ID'] 3 0 -->
<!-- SESSION['cookieID'] 4 118503675993 -->
<!-- SESSION['cookieID'] 5 0 COOKIE['ID'] 6 0 -->
<!-- Stored Cookie is 0 -->
<!-- SESSION['cookieID'] 7 0 -->
<!-- cookieTime 1185036759 -->
<!-- cookieRand 93 -->
As can be seen below, output 4 should occur if !$_SESSION["cookieID"] and
if !$_StoredCookie, 5 and 6 should only happen if the inverse is true.
CODE (not closed because this is a partial):
<?php
$one = 0;
$two = 0;
$three = 0;
$four = 0;
$five = 0;
$six = 0;
$seven = 0;
session_start();
if (!$dbHandle)
{
$connectDB = "host=***** hostaddr=***** dbname=*****
user=***** password=*****";
$dbHandle = pg_connect( $connectDB );
}
$uno = $_COOKIE["ID"]; $duos = $_SESSION["cookieID"];
if (is_numeric($_COOKIE["ID"]))
{ $sCookie = pg_query( $dbHandle, "SELECT cookie_id FROM cookies WHERE
cookie_id = ".$_COOKIE["ID"].";");
$storedCookie = pg_num_rows($sCookie);
$one = $_COOKIE["ID"]; }
if (!$_SESSION["cookieID"])
{
if ($storedCookie)
{
$_SESSION["cookieID"] = $_COOKIE["ID"];
$two = $_SESSION["cookieID"]; $three = $_COOKIE["ID"];
$themeID = pg_query( $dbHandle, "SELECT theme_id FROM cookies WHERE
cookie_id = ".$_COOKIE["ID"].";");
$_SESSION["themeID"] = pg_fetch_result($themeID, 0, 0);
setcookie("ID", $_SESSION["cookieID"], time()+604800, '/',
'.odubtaig.net');
}
else
{
$cookieTime = time(); $cookieRand = rand(0, 100); $_SESSION["cookieID"]
= $cookieTime.$cookieRand; pg_query( $dbHandle, "INSERT INTO cookies
(cookie_id, theme_id) VALUES (".$_SESSION["cookieID"].", 1);");
$four = $_SESSION["cookieID"];
setcookie("ID", $_SESSION["cookieID"], time()+604800, '/', '.odubtaig.net');
$_SESSION["themeID"] = "1";
}
}
else
{
if($storedCookie)
{
if ($_SESSION["cookieID"] != $_COOKIE["ID"])
{ $_SESSION["cookieID"] = $_COOKIE["ID"]; }
$thisTheme = pg_query( $dbHandle, "SELECT theme_id FROM cookies WHERE
cookie_id = ".$_COOKIE["ID"].";");
$_SESSION["themeID"] = pg_fetch_result($thisTheme, 0, 0);
$five = $_SESSION["cookieID"]; $six = $_COOKIE["ID"];
}
else
{
$cookieTime = time(); $cookieRand = rand(0, 100);
$_SESSION["cookieID"] = $cookieTime.$cookieRand;
pg_query( $dbHandle, "INSERT INTO cookies (cookie_id, theme_id) VALUES
(".$_SESSION["cookieID"].", 1);");
$seven = $_SESSION["cookieID"];
setcookie("ID", $_SESSION["cookieID"], time()+604800, '/',
'.odubtaig.net'); $_SESSION["themeID"] = "1";
}
}
$thisAddy = $_SERVER["HTTP_HOST"];
if ($_POST["theme"])
{
$_SESSION["themeID"] = $_POST["theme"];
pg_query( $dbHandle, "UPDATE cookies SET theme_id =
".$_SESSION["themeID"]." WHERE cookie_id = ".$_SESSION["cookieID"].";");
}
echo "<!-- Initial cookieID = ".$uno." Initial Serv.cookieID = ".$duos." -->
";
echo "<!-- COOKIE['ID'] 1 ".$one." -->
";
echo "<!-- SESSION['cookieID'] 2 ".$two." COOKIE['ID'] 3 ".$three." -->
";
echo "<!-- SESSION['cookieID'] 4 ".$four." -->
";
echo "<!-- SESSION['cookieID'] 5 ".$five." COOKIE['ID'] 6 ".$six." -->
";
echo "<!-- Stored Cookie is ".$storedCookie." -->
";
echo "<!-- SESSION['cookieID'] 7 ".$seven." -->
";
echo "<!-- cookieTime ".$cookieTime." -->
";
echo "<!-- cookieRand ".$cookieRand." -->
";
Navigation:
[Reply to this message]
|