SESSION中的参数不会出现在其他php文件

时间:2017-02-09 16:21:21

标签: php joomla session-variables

我有两个文件,比如这两个:

<?php  
session_start();

class test{
    public function login($code){ 

        $app = JFactory::getApplication('site');
        $db    = JFactory::getDBO();
        $query = $db->getQuery(true);

        $query->select(array('id'))
            ->from($db->quoteName('#__users'))
            ->where($db->quoteName('code') . " = " . $db->quote($code));

        $db->setQuery($query);//execute query             
        $results = $db->loadObjectList();//get results

        if ($results[0] != null) {
            $this->createSession($results[0]);
            header("refresh:2;url=second_file.php");
        } 

        return json_encode($results);
    }

    public function createSession($LoginInfo){ 
        $_SESSION['userId']=$LoginInfo->id;
    }
}

?>

和另一个像这样的php文件:

<?php 
 session_start();
?>
<!DOCTYPE html>
<html lang="en">
<head></head>
<body>
  <?php 
    echo $_SESSION['userId'];
  ?>
</body>
</html>

在第二页似乎会话中没有信息,我无法获得“userId”参数。

PS:第一类php文件由另一个php文件调用,其中有类似的东西:

require_once('test.class.php');
$mainframe = new test
if ($_GET['code']!=null) echo $mainframe->login($_GET['code']);

我在哪里做错了?感谢。

PPS:所有这些文件都托管在altervista.org中,并且安装了Joomla CMS。

0 个答案:

没有答案