Is it possible to access a Global variable declared in a file, e.g. a header.php file, from another external PHP file named content.php that has been loaded with an AJAX call, without using GET or POST?
e.g.
index.php:
<?php
include 'header.php'; //The global variable $SESSIONID is defined in this file
echo '<div id="for-content"></div>';
include 'footer.php';
?>
header.php
<?php
$SESSIONID = "asdf";
?>
content.php:
<?php
echo $SESSIONID;
?>
And the AJAX call:
$("#for-content").load("content.php");
No it isn't possible to get access to the global variable. You have to include
header.phpagain. AJAX is loading the document (in your casecontent.php) asynchronous with a complete new http-request. So it will loadingcontent.phpwithout any data.The only possible solution is to send
$SESSIONIDwith AJAX-Call viaPOST:or
GET