一个会话已经开始

一个会话已经开始

本文介绍了“未定义变量:_SESSION"对比.“一个会话已经开始"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿.我有一些 php 脚本.其中一个我有代码 session_start(),当我在另一个脚本中再次有 session_start() 时,我收到通知:

注意:会话已经开始...

这是合乎逻辑的.但是当我删除它时,我收到错误/通知:

注意:未定义变量:_SESSION

为什么?我该如何解决?当我在脚本中有两个位置 session_start() 时,脚本工作正常(只有一点点通知),但当我没有两个 session_start() 时,脚本根本不起作用.

是唯一的解决方案

error_reporting(E_ALL ^ E_NOTICE);

在我的脚本中?忽略通知不是不好的做法吗?

我的部分代码:

 试试 {//session_start();$STH = DB::prepare ("更新用户 SET DJ_name=?, DJ_showname=?WHERE id=?");$STH->execute(array($_POST['DJ_name'], $_POST['DJ_showname'], $_SESSION['userid']));pre_dump($_SESSION);$_SESSION['DJ_name'] = $_POST['DJ_name'];$_SESSION['DJ_showname'] = $_POST['DJ_showname'];}

输出:

注意:未定义变量:_SESSION in D:.....\main.php on line 19

注意:未定义变量:_SESSION in D:.....\main.php on line 21

预转储代码:

 函数 pre_dump($var){echo '

';var_dump($var);echo '</pre>';}
解决方案

我自己发现了错误.在我的脚本中某处有一个我没有注意到的 session_start().现在似乎一切正常.

Hey.I have some php scripts. In one of them i have the code session_start(), and when I in another script again have session_start() i get the notice:

Thats logical. But when I remove it I get the error/notice:

Why? And how do I fix it? The scripts works fine when I have session_start() two places in the script (only get an little notice), but doesn't work at all when I doesn't have two session_start().

Is the only solution to have an

error_reporting(E_ALL ^ E_NOTICE);

in my script? And isn't that bad practice to just ignore notices?

Edit:

Parts of my code:

            try {
            //session_start();

            $STH = DB::prepare  (   "UPDATE users SET DJ_name=?, DJ_showname=? WHERE id=?" );
            $STH->execute(array($_POST['DJ_name'], $_POST['DJ_showname'], $_SESSION['userid']));

            pre_dump($_SESSION);

            $_SESSION['DJ_name']        =   $_POST['DJ_name'];
            $_SESSION['DJ_showname']    =   $_POST['DJ_showname'];
        }

Output:

pre_dump code:

    function pre_dump($var)
{
    echo '<pre>';
    var_dump($var);
    echo '</pre>';
}
解决方案

I found the error myself.Had an session_start() somewhere in my script that I didn't notice. Everything seems working now.

这篇关于“未定义变量:_SESSION"对比.“一个会话已经开始"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 08:14