0

我尝试将 $_SESSION["avalue"] 从 request.php 文件扔到 response.php 文件,如下所示:
request.php:

<?php
    $_SESSION["across"] = "across Session";
?>


<script type="text/javascript"> 
  function requestExample(){
    xmlhttp.open("POST", "../response.php?Name=Example", true);
    xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlhttp.send();
  }
</script>

... .......
Response.php:

<?php
if(isset($_GET["Name"]))
{
    $name = $_GET["Name"];
    switch($name){
        case "Example":
            echo $_SESSION["across"];
            break;
                ......
    }
}

?>

我收到错误:未定义的索引:在 ......../response.php 中

4

1 回答 1

0

我通过使用下面的代码得到了它。[来源 http://docs.joomla.org/How_to_access_session_variables_set_by_an_external_script]

define( '_JEXEC', 1 );
define( 'DS', DIRECTORY_SEPARATOR );
define('JPATH_BASE', dirname(__FILE__) );


require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' );
require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' );

$mainframe =& JFactory::getApplication('site');
$mainframe->initialise();


$session =& JFactory::getSession();
$user = $session->get( 'across' );

谢谢!

于 2012-12-01T10:16:36.527 回答