1

I've got a perfectly functioning site which uses sessions. The only exception, is one particular page. The page performs some DB SELECTS, verification stuff, etc. etc. Then, later on, in the HTML part, ive got a tag. Between that, ive got

<?php
    $classes = explode(",", $_SESSION['classes']);
    foreach ($classes as $class) {
        echo "<option>".$class."</option>";
    }
?>

Now $_SESSION['classes'] is a comma separated string. Example: "10 A,11 D,12 C" here's the weird part, when i load this page, everything works perfectly, and i get a drop-down select with options 10 A, 11 D and 12 C... but, when i refresh the page, I get a dropdown box with only one option: Array

Yes, it just says Array.... no other options.

And no, i haven't set the value to anything else after that PHP block. in fact, i dont have another PHP block after this one

To debug it, I added a php block with the code: echo $_SESSION['classes']; after the </select> tag, and the first page load, it said 10 A,11 D,12 C. After refresh, it said Array

Then i tried var_dump($_SESSION); and it said ["classes"]=> &string(9) "11 A,10 C" Heres the weirdest part: After refresh, it said ["classes"]=> &array(2) { [0]=> string(4) "11 A" [1]=> string(4) "10 C" } and on another refresh, it said ["classes"]=> &array(1) { [0]=> string(5) "Array" }

This only happens on my web host though, not on my local server. And, only on this page

I have no idea what's causing this, or how to fix it

4

2 回答 2

1

您可能已经register_globals打开,所以在某些时候$classes会混在一起。$_SESSION['classes']

你应该把它们关掉。(这就是为什么。)

或者,如果由于某种原因无法关闭它们,请更改变量名称。

于 2013-07-15T13:30:30.197 回答
0

知道了!

这是我的新代码:

<?php
    $classesBeingTaught[] = explode(",", $_SESSION['classes']);
    foreach ($classesBeingTaught[0] as $classBeingTaught) {
        echo "<option>".$classBeingTaught."</option>";
    }
?>
于 2013-07-15T13:46:11.777 回答