CodeIgniter Forums
Flashdata disappears when certain ASCII codes appear in message - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Flashdata disappears when certain ASCII codes appear in message (/showthread.php?tid=55445)



Flashdata disappears when certain ASCII codes appear in message - El Forum - 10-26-2012

[eluser]Simple Gifts[/eluser]
Hi, folks. I've been chasing a flashdata problem for a few hours, and finally found a simple test to illustrate the problem (CI 2.1). I'm running Apache 2.2.21 on XP.

This works just fine:
Code:
$strTest =' "Hello World" ';
$this->session->set_flashdata('error', $strTest);

However, this fails, showing no flashdata:
Code:
$strTest =' “Hello World” ';
$this->session->set_flashdata('error', $strTest);

Note that in the second example, the only difference is the use of the left and right double quotes (ASCII “ and &#148Wink, instead of the more common double quote (ASCII &#34Wink.

Unfortunately, htmlspecialchars() doesn't escape these double quote characters.

Am I missing something? Is there a character set restriction that I'm not aware of?

Thanks for any help.


Flashdata disappears when certain ASCII codes appear in message - El Forum - 10-26-2012

[eluser]Simple Gifts[/eluser]
After a little more digging, this appears to be a cookies problem.

The following code
Code:
setcookie('myQuoteTest',     ' "Hello World" ');
setcookie('myQuoteTestFail', ' “Hello World” ');
print_r($_COOKIE);

produces the following:
Code:
Array
(
    [myQuoteTest] =>  "Hello World"
    [myQuoteTestFail] =>  Hello World
    ...
)

The double quotes get stripped from the failing cookie. The CI session cookie gets confused because the flashdata component of the session variable is two characters shorter than expected.

Here's the CI session cookie for the failing flashdata:
Code:
[lnp_ci_session] => a:7:{
            s:10:"session_id";
            s:32:"9bf1eacee64a35e8f3f3eaa3abf210c9";
            s:10:"ip_address";
            s:9:"127.0.0.1";
            s:10:"user_agent";
            s:99:"Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.4 (KHTML, like Gecko) Chrome/22.0.1229.94 Safari/537.4";
            s:13:"last_activity";
            i:1351286819;
            s:9:"user_data";
            s:0:"";
            s:15:"flash:old:error";
            s:15:" "Hello World" ";
            s:15:"flash:new:error";
            s:15:" Hello World ";   // note that the embedded double quotes are missing
                                    // and the string is only 13 characters long
            }56f72386e3e36b0ce9805c245db1895c

Note sure where to take this next, since it seems to be a php situation. Any thoughts?