Igo*_*kin 4 php byte-order-mark sessionid yii
因为我已经将yii应用程序移动到另一个共享主机,并且应用程序是runnig ... index.php?r =使用登录凭据的站点/登录我得到了warnig:
session_regenerate_id(): Cannot regenerate session id - headers already sent
Run Code Online (Sandbox Code Playgroud)
该actionLogin
"的代码:
public function actionLogin($name = null )
{
$model=new LoginForm;
if ($name) $model->username = $name;
if(isset($_POST['ajax']) && $_POST['ajax']==='login-form')
{
echo CActiveForm::validate($model);
Yii::app()->end();
}
if(isset($_POST['LoginForm']))
{
$model->attributes=$_POST['LoginForm'];
// validate user input and redirect to the previous page if valid
if (headers_sent($filename, $linenum))
{
echo "Headers have been sent in {$filename} line number is {$linenum}\n"
exit;
}
if($model->validate() && $model->login())
$this->redirect(Yii::app()->user->returnUrl);
}
// display the login form
$this->render('login',array('model'=>$model));
}
Run Code Online (Sandbox Code Playgroud)
文档和论坛都谈到了BOM的问题.然而在我的记事本++中,所有文件都保存为UTF-8而没有BOM. 我应该对文件进行特殊检查吗?哪个?或者可能有其他原因导致错误?
我添加了headers_sent($filename, $linenum)
函数(参见上面的代码)来跟踪发送的标题但没有结果.
cha*_*ool 10
使用
ob_start()
Run Code Online (Sandbox Code Playgroud)
在文件的开头.
通常,当我们在回显或打印后发送标头时会出现此错误。如果此错误出现在特定页面上,请确保该页面在调用 start_session() 之前没有回显任何内容。
不可预知的错误示例:
<?php //a white-space before <?php also send for output and arise error
session_start();
session_regenerate_id();
//your page content
Run Code Online (Sandbox Code Playgroud)
有时它在您的本地主机计算机中无关紧要,但在您的远程服务器中却很重要。