【问题标题】:"Warning: ini_set(): A session is active" error“警告:ini_set():会话处于活动状态”错误
【发布时间】:2015-01-04 05:54:16
【问题描述】:

我正在使用 Heroku 和 SQL 创建一个带有登录用户数据库的页面。我无法从 PHP 和 MYSQL 翻译这个。作为过渡的一部分,我不断在我网站的每个页面顶部收到此错误,但我终其一生都无法弄清楚为什么或如何摆脱它:

警告:ini_set():会话处于活动状态。此时您无法在第 56 行的 /app/vendor/symfony/http-foundation/Symfony/Component/HttpFoundation/Session/Storage/Handler/NativeFileSessionHandler.php 中更改会话模块的 ini 设置

我尝试阅读此内容,但没有得到任何结果: ErrorException: Warning: ini_set(): A session is active. You cannot change the session module's ini settings at this time in /../../

这是我页面的登录页面部分:

$app->post('/login/', function() use($app)  {

    // configuration
    //require("../includes/config.php");
$usernameExists = false;
$emailExists = false ; 

$username = $app['request']->get('username');
$password = $app['request']->get('password');

$st = $app['pdo']->prepare("SELECT * FROM users where username = ?") ;
$st -> execute(array($username));
$userinfo = array() ; 
 while ($row = $st->fetch(PDO::FETCH_ASSOC)) {
    $app['monolog']->addDebug('Row ' . $row['username']);
    $userinfo[] = $row;
  }   

if (count($userinfo) == 1  )
{
     $row = $userinfo[0];
     $salt = openssl_random_pseudo_bytes(64) ; 
     if (crypt($password, $salt) == crypt($row['password'], $salt))
     {
        //set session id
        session_start();
        $app['session']->set('user', array('username' => $username));
           return $app->render('myshows.php'/*, array(
    'names' => $usernames ) */
      );
     }
     else 
     {
        return $app['twig']->render('login_form.twig', array('incorrectlogin' => 1 ));
     }
}

if ($userinfo == null )
{
return $app['twig']->render('login_form.twig' , array(
    'incorrectlogin' => 1 ));
}
}) ; 

这是我当前的 php.ini 文件:

; php options
date.timezone = UTC
 session.auto_start = 0
; hhvm specific 
hhvm.log.level = Warning
hhvm.log.always_log_unhandled_exceptions = true
hhvm.log.runtime_error_reporting_level = 8191
hhvm.mysql.typed_results = false

【问题讨论】:

  • 确保 session.auto_start 已禁用。
  • 顺便说一句:不需要session_start();。 Symfony2 自己启动会话。
  • 我添加了我的 php.ini 文件,保存在:\vendor\heroku\heroku-buildpack-php\conf\hhvm

标签: php session heroku


【解决方案1】:

我找到了答案!我不小心包含了 session_start();在我的配置文件中。现在一切都好起来了。

【讨论】:

    【解决方案2】:

    配置文件中不需要这行

    session_start(); //需要调用PHP的会话对象才能访问它 当您加载会话库时,它的构造函数会为您执行这些操作。

    【讨论】:

      猜你喜欢
      • 2015-05-21
      • 2012-11-12
      • 2018-05-21
      • 1970-01-01
      • 2015-12-25
      • 2020-04-26
      • 2018-11-26
      • 1970-01-01
      • 2020-07-14
      相关资源
      最近更新 更多