[wp-trac] [WordPress Trac] #15820: Under a specific condition, session variables declared in templates exhibit unexpected behavior
WordPress Trac
wp-trac at lists.automattic.com
Tue Dec 14 21:07:46 UTC 2010
#15820: Under a specific condition, session variables declared in templates exhibit
unexpected behavior
-------------------------+-------------------------------------------------
Reporter: dougwaltman | Owner:
Type: defect | Status: new
(bug) | Milestone: Awaiting Review
Priority: normal | Version: 3.0.3
Component: Themes | Keywords: session, header, bloginfo, variable
Severity: minor |
-------------------------+-------------------------------------------------
I believe I have discovered a very peculiar bug that occurred when I tried
to set a single session variable in a template file, "header.php", and
call it again after refreshing the page. I have written a quick snippet
of code that can be used to replicate the issue. This code will:
* Start the session
* Display some HTML
* Create an array of values
* Shuffle the values
* Display the first value as "new"
* Display the session variable of the last stored value
* Set the session variable to the "new" one
Add the following code to the top of "header.php" in any template:
{{{
<?php
session_start();
?>
<link rel="icon" href="<? bloginfo('template_url') ?>/images/x" />
<?php
$myarray = array(
'a','b','c','d','e'
);
shuffle($myarray);
echo "<pre>New: ".$myarray[0];
echo "\nOld: ".$_SESSION['last_one_displayed'];
$_SESSION['last_one_displayed'] = $myarray[0];
exit;
?>
}}}
After refreshing the page several times, you will notice that the value
for "old" isn't matching the "new" value from the previous refresh. The
code will behave as expected if you do any number of things, including:
* Change 'rel="icon"' to anything else, suchas 'rel="icons"' or
'rely="icon"'
* Remove the 'rel="icon"' attribute entirely
* Remove the 'x' from the end of the url
* Remove the '<? bloginfo('template_url') ?>' snippet
* Move the '<link...' line below the rest of the code
I suspect that this bug has something to do with the code that compiles
and displays the template.
--
Ticket URL: <http://core.trac.wordpress.org/ticket/15820>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list