Forum Moderators: coopster
Assuming my session variable $_SESSION["logged"] is properly set to "yes", the script in page1.php will display "yes" only once:
page1.php
---------
<? session_start();?>
<html>
<body>
<? echo $_SESSION["logged"]?>
<script language="javascript" src="http://page2.php"> </script>
</body>
</html>
page2.php
---------
<?
session_start();
<? echo $_SESSION["logged"]?>
?>
Called directly, page2.php will display "yes", but called through the js include of page1, it will not.
And that is my mystery of the day!
Use PHP to pull the PHP session variable and write it's value into a Javascript variable on the page:
<? if (isset($_SESSION["logged"])) { echo "<script type='text/javascript'>sesslogged=".$_SESSION["logged"].";</script>"; } ?> THEN it will be available to Javascript, either to an included script or to a script on the page following the variable value assignment.
page1.php
<? session_start();?>
<html>
<body>
<? echo $_SESSION["logged"]?>
<script language="javascript" src="http://page2.php?<?php echo strip_tags(SID);?>"> </script>
</body>
</html>
page2.php
<?
session_start();
echo $_SESSION["logged"];
?>
This should work according to php manual [php.net]
Best regards
Michal CIbor