0

I have the $user array that contains data with special characters. It seems like each element of $user that contains special characters can't render properly after they are stored in a session.

Here is my code:

    <?php
session_start();

include_once('../application/classes/DataLayer.class.php');

    $dl = new DataLayer();
    $user = $dl->doLogin($_POST['email_sub'], $_POST['password_sub']);

    if(isset($user)) {
            foreach($user as $detail_array => $detail){
            $fn = html_entity_decode($user['fn']);      
            $ln = html_entity_decode($user['ln']);      
        }
        var_dump($fn, $ln); // $fn and $ln display well here

        $_SESSION['user'] = $user;
        $_SESSION['fn'] = $fn;
        $_SESSION['ln'] = $ln;
        var_dump($_SESSION['fn'], $_SESSION['ln']); // $_SESSION['fn'], $_SESSION['ln'] display well here too
    }
    else {
    //do something here
    }
?>

Any help would be appreciated. Sorry for my bad english.

lomse
  • 4,045
  • 6
  • 47
  • 68

1 Answers1

0

Use the function from this link https://stackoverflow.com/a/8454838/997178 to encode the data for output
Use encode_output_vars function , param $vars is your session data ... return value will be a single element encoded for output or an array with all elements encoded , depending what your parameter is .
Or just use php function htmlentities for your session data before you output it . Here is link http://php.net/manual/en/function.htmlentities.php

Community
  • 1
  • 1
Tudor
  • 1,133
  • 1
  • 12
  • 28
  • Thanks for the quick answer, the functions worked great. Using the var_dump() function I got: éâgl . The only problem is that html_entity_decode(éâgl) is suppose to give me this string "éâgl" but end up giving me "éâgl". What am I missing. (I am using the meta ) – lomse Jan 25 '12 at 12:34
  • try to set the same charset "iso-8859-1" for the html entity decode function... its the 3rd param ... the default charset for that function is UTF-8 . Read more about this function here http://php.net/manual/en/function.html-entity-decode.php . – Tudor Jan 25 '12 at 16:56