1.php如下:<?php
if (!isset($_SESSION)) {
    session_start();
}
$_SESSION["swhowimg"] = "allen";
?>
2.php如下:
<?php
if (!isset($_SESSION)) {
    session_start();
}
print $_SESSION["swhowimg"];
?>先打开1.php显示值allen,后打开2.php却提示错误:Notice: Undefined index: swhowimg in D:\site\dianphp\agent\2.php on line 6
PHP Notice: Undefined index: swhowimg in D:\site\dianphp\agent\2.php on line 6 还请各位帮小弟看看,是不是php环境哪配好?

解决方案 »

  1.   

    這個只是警告啊.
    是否是你的session保存路徑有問題呢?
      

  2.   

    去掉if(!isset($_SESSION))判断,要使用session,每个php文件中都需要session_start();
      

  3.   

    php.ini 中
    session.save_path = "c:\temp"
    session.auto_start = 1
    去掉if(!isset($_SESSION))判断提示:Notice: A session had already been started - ignoring session_start() in D:\site\dianphp\agent\2.php on line 2
      

  4.   

    2.php 的$_SESSION["swhowimg"]没有值啊 ,很纠结
      

  5.   

    你的2.php不是从1.php跳转过去的啊?
      

  6.   

    session.auto_start = 0
    最好不要让其自动开始session程序前面:
    session_save_path("你站点下某个可读写的目录");
    session_start();
      

  7.   

    1.php
    <?php
    session_start();
    $_SESSION['swhowimg'] = "sadf";
    ?>
    <a href="2.php">2.php</a>2.php
    <?php
    session_start();
    echo $_SESSION['swhowimg'];
    ?>
      

  8.   

    +1
    用到 session 都要 session_start();
      

  9.   

    目前php.ini 里 session.auto_start = 01.php
    <?php
      session_start();
    $_SESSION["swhowimg"] = "allen";
    print $_SESSION["swhowimg"];
    ?>
    <a href="2.php">2.php</a>2.php
    <?php
    session_start();
    echo $_SESSION['swhowimg'];
    ?>
    现在按上面的测试,还是提示没有定义的,没有值:
    Notice: Undefined index: swhowimg in D:\site\dianphp\agent\2.php on line 7
    PHP Notice: Undefined index: swhowimg in D:\site\dianphp\agent\2.php on line 7 
      

  10.   

    2.php里 你那个if()也不要了 本身逻辑就有错 然后 session_start()以前不能有任何输出 一个字符都不可以建议你 学习一下 在MySQL制定session处理器 因为你这样 驻留内存的seesion文件太多 就吃不消了