Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Read session value with Javascript

Is it possible to read a session value with Javascript?

For example, if I assigned a value into a session in PHP:

$_SESSION['msg'] = "ABC Message";

Is it possible to read $_SESSION['msg'] with Javascript?

like image 340
Jin Yong Avatar asked Apr 16 '09 04:04

Jin Yong


1 Answers

A very simple way is to generate the JavaScript with some PHP code:

<script type="text/javascript">
    <?php echo 'var msg = "'.json_encode($_SESSION['msg']).'";';
</script>
like image 148
harto Avatar answered Nov 13 '22 15:11

harto