I'm tring to pass a session variable to javascript but not have success. Searching stackoverflow i have found this discussion: Passing Session variables to javascript
in my custom.js i have on header
<?php session_start(); ?>
.. /// js code
strActionPage = CurrentPath + "upload_file.php?ation=store&session_user_id=<?php echo $_SESSION['session_user_id']; ?> "; //the ActionPage's file path
but i cant get session variable from upload_file.php page
where do I wrong?
Tks to all
Wait, you're using PHP on a JavaScript file (that's what your OP says)? Not gonna work. You're going to have to pass it to a JavaScript function as a parameter like so:
<?php
session_start();
// HTML and stuff
<script type="text/javascript" src="custom.js"></script>
<script type="text/javascript">
passSession("<? echo $_SESSION['session_user_id']; ?>");
</script>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With