Forums
This topic is locked
Get php session
Posted 07 Sep 2007 19:56:26
1
has voted
07 Sep 2007 19:56:26 Devorah Fleisher posted:
How can I get a php session variable into a javascript variable.ie:
productID = "<?php $_SESSION['productID'] ?>"
when I try to see what the variable contains with
alert (productID);
I do not get any data.
What did I do wrong?
Replies
Replied 13 Sep 2007 14:56:28
13 Sep 2007 14:56:28 Georgi Kralev replied:
Hi Devorah,
Make sure that you have start up the session and your session variable has value.
For example the following code work without any problems on my computer:
<i>
<?php
<b>session_start(); </b>
<b>$_SESSION['data'] = 1;</b> // store session data
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="www.w3.org/1999/xhtml">
<head>
</head>
<SCRIPT LANGUAGE="JavaScript">
var productID = "<?php <b>echo $_SESSION['data'];</b> //retrieve data ?>";
alert (productID);
</SCRIPT>
<body>
Display Session data with JavaScript
</body>
</html></i>
I hope this helps.
Regards,
Georgi Kralev
----------------------------------
Support - www.DMXzone.com
Make sure that you have start up the session and your session variable has value.
For example the following code work without any problems on my computer:
<i>
<?php
<b>session_start(); </b>
<b>$_SESSION['data'] = 1;</b> // store session data
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="www.w3.org/1999/xhtml">
<head>
</head>
<SCRIPT LANGUAGE="JavaScript">
var productID = "<?php <b>echo $_SESSION['data'];</b> //retrieve data ?>";
alert (productID);
</SCRIPT>
<body>
Display Session data with JavaScript
</body>
</html></i>
I hope this helps.
Regards,
Georgi Kralev
----------------------------------
Support - www.DMXzone.com