Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pass Session Variable to javascript [duplicate]

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

like image 649
user2112020 Avatar asked Sep 11 '26 22:09

user2112020


1 Answers

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>
like image 135
Descartes Avatar answered Sep 13 '26 12:09

Descartes