简体   繁体   中英

PHP Session Variable not being passed to JS variable

I'm trying to save a PHP Session variable called user_login in a JS variable called name. I need to get the value from the session variable. Nothing worked so far and all I am getting passed to my alert is:

<?php echo rawurlencode($_SESSION['user_login']); ?>

 $(document).ready(function() { var name = decodeURIComponent("<?php echo rawurlencode($_SESSION['user_login']); ?>"); alert(name); setTimeout(function() { if (name.length > 0) { $('h3.name').html(name); $('h3.name').css({ display: 'block' }); } }, 200); }); 

Seems the php code isn`t evaluated.

Check if the php works for this file.

The source of the page being served by the web server should look like this:

    **decodeURIComponent("some value");**

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM