|
|
|
#1 |
|
Messages: n/a
Hébergeur: |
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 , not setting , updating , 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 value that isn't stored in the database (and, so far, when $_SESSION has /a/ _id value), while the desired result of a new db row and a reset and session value are achieved, the variables I'm using to trace what's happening report values as though the 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 ID = 118503664987 Initial Serv.ID = 118503664987 --> <!-- ['ID'] 1 118503664987 --> <!-- SESSION['ID'] 2 0 ['ID'] 3 0 --> <!-- SESSION['ID'] 4 0 --> <!-- SESSION['ID'] 5 118503664987 ['ID'] 6 118503664987 --> <!-- Stored is 1 --> <!-- SESSION['ID'] 7 0 --> <!-- Time --> <!-- Rand --> Output under Konqueror (hoped for output) is: <!-- Initial ID = 118488413231 Initial Serv.ID = --> <!-- ['ID'] 1 118488413231 --> <!-- SESSION['ID'] 2 0 ['ID'] 3 0 --> <!-- SESSION['ID'] 4 118503675993 --> <!-- SESSION['ID'] 5 0 ['ID'] 6 0 --> <!-- Stored is 0 --> <!-- SESSION['ID'] 7 0 --> <!-- Time 1185036759 --> <!-- Rand 93 --> As can be seen below, output 4 should occur if !$_SESSION["ID"] and if !$_Stored, 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 = $_["ID"]; $duos = $_SESSION["ID"]; if (is_numeric($_["ID"])) { $s = pg_query( $dbHandle, "SELECT _id FROM WHERE _id = ".$_["ID"].";"); $stored = pg_num_rows($s); $one = $_["ID"]; } if (!$_SESSION["ID"]) { if ($stored) { $_SESSION["ID"] = $_["ID"]; $two = $_SESSION["ID"]; $three = $_["ID"]; $themeID = pg_query( $dbHandle, "SELECT theme_id FROM WHERE _id = ".$_["ID"].";"); $_SESSION["themeID"] = pg_fetch_result($themeID, 0, 0); set("ID", $_SESSION["ID"], time()+604800, '/', '.odubtaig.net'); } else { $Time = time(); $Rand = rand(0, 100); $_SESSION["ID"] = $Time.$Rand; pg_query( $dbHandle, "INSERT INTO (_id, theme_id) VALUES (".$_SESSION["ID"].", 1);"); $four = $_SESSION["ID"]; set("ID", $_SESSION["ID"], time()+604800, '/', '.odubtaig.net'); $_SESSION["themeID"] = "1"; } } else { if($stored) { if ($_SESSION["ID"] != $_["ID"]) { $_SESSION["ID"] = $_["ID"]; } $thisTheme = pg_query( $dbHandle, "SELECT theme_id FROM WHERE _id = ".$_["ID"].";"); $_SESSION["themeID"] = pg_fetch_result($thisTheme, 0, 0); $five = $_SESSION["ID"]; $six = $_["ID"]; } else { $Time = time(); $Rand = rand(0, 100); $_SESSION["ID"] = $Time.$Rand; pg_query( $dbHandle, "INSERT INTO (_id, theme_id) VALUES (".$_SESSION["ID"].", 1);"); $seven = $_SESSION["ID"]; set("ID", $_SESSION["ID"], time()+604800, '/', '.odubtaig.net'); $_SESSION["themeID"] = "1"; } } $thisAddy = $_SERVER["HTTP_HOST"]; if ($_POST["theme"]) { $_SESSION["themeID"] = $_POST["theme"]; pg_query( $dbHandle, "UPDATE SET theme_id = ".$_SESSION["themeID"]." WHERE _id = ".$_SESSION["ID"].";"); } echo "<!-- Initial ID = ".$uno." Initial Serv.ID = ".$duos." --> "; echo "<!-- ['ID'] 1 ".$one." --> "; echo "<!-- SESSION['ID'] 2 ".$two." ['ID'] 3 ".$three." --> "; echo "<!-- SESSION['ID'] 4 ".$four." --> "; echo "<!-- SESSION['ID'] 5 ".$five." ['ID'] 6 ".$six." --> "; echo "<!-- Stored is ".$stored." --> "; echo "<!-- SESSION['ID'] 7 ".$seven." --> "; echo "<!-- Time ".$Time." --> "; echo "<!-- Rand ".$Rand." --> "; |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
On 21 Jul, 17:57, Paul Duffy <odubt...@yahoo.dot.coh.dot.yoo.kay>
wrote: > 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 , not setting , updating > , 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 value that isn't stored > in the database (and, so far, when $_SESSION has /a/ _id value), > while the desired result of a new db row and a reset and session > value are achieved, the variables I'm using to trace what's happening > report values as though the 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. > You're more likely to get a reply if you can reduce your code down to something which demonstrates the problem *and* *nothing* *else* I would suggest you look at the paths on the . C. |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
>
> You're more likely to get a reply if you can reduce your code down to > something which demonstrates the problem *and* *nothing* *else* > > I would suggest you look at the paths on the . > > C. OK, I've tried to shorten it by stripping out the specifics of the code. This is a test case for when a browser sends a bad ID. At a new session outputs should only be for $uno, $one, $four, $Time and $Rand (no session ID and not stored). Whether it's a new session or not, Firefox gets $uno, $duos, $one, $five and $six (has session ID and is stored) but not $four, $Time or $Rand. Also, $stored comes back as 1 instead of 0 which should not happen if the psql query was done before the ID was stored. What's extra confusing is that, otherwise, it behaves as it should, a new value is inserted into the database, the value held by FF changes to this new value and all seems well. The only thing I can think of that could be causing this would be FF calling the page again when a new is set and reloading it in which case the values would be valid, but this seems an unorthodox way for a browser to behave and could make debugging an issue in future. > CODE (not closed because this is a partial): > > <?php > > if (is_numeric($_["ID"])) > { Check exists > $stored = TRUE/FALSE(1/0);} > > if (!$_SESSION["ID"]) > { > if ($stored) set session ID > else set and session ID > } > else > { > if($stored) > { > if ($_SESSION["ID"] != $_["ID"]) > { $_SESSION["ID"] = $_["ID"]; } > Set theme > } > else > { set new and reset session ID > } > } > > echo "<!-- Initial ID = ".$uno." Initial Serv.ID = > ".$duos." --> > "; > echo "<!-- ['ID'] 1 ".$one." --> > "; > echo "<!-- SESSION['ID'] 2 ".$two." ['ID'] 3 ".$three." --> > "; > echo "<!-- SESSION['ID'] 4 ".$four." --> > "; > echo "<!-- SESSION['ID'] 5 ".$five." ['ID'] 6 ".$six." --> > "; > echo "<!-- Stored is ".$stored." --> > "; > echo "<!-- SESSION['ID'] 7 ".$seven." --> > "; > echo "<!-- Time ".$Time." --> > "; > echo "<!-- Rand ".$Rand." --> > "; |
|
![]() |
| Outils de la discussion | |
|
|