php版本?
<?
//test1.php
session_start(); 
$_SESSION['username'] = test; 
header("Location:test2.php"); 
?> <?php
//test2.php 
session_start(); if ($_SESSION['username']) 

    print "用户名:".$_SESSION['username']; 

else 

    print "unset"; 

?>

解决方案 »

  1.   

    多谢指教。我试了一下,用你的代码也不行。
    PHP版本:4.0.6
      

  2.   

    试试这样行不行:
    //test1.php
    <? 
    session_start(); 
    $_SESSION["username"]='test'; 
    header("Location:test2.php"); 
    ?> //test2.php
    <?php 
    session_start(); 
    ?>
    <html>
    <head>
    <title>php页面</title>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    </head>
    <body>
    <?PHP
    if ( isset($_SESSION["username"]) ) 

        print "用户名:".$_SESSION['username']; 

    else 

        print "unset"; 

    ?>
    </body>
    </html>
      

  3.   

    我的可以的,我的php是:4.3.3
    test1.php
    <?
    session_start();
    $_SESSION["username"]="hello,world";
    header("Location:test2.php");
    ?>
    test2.php
    <?
    session_start();
    if($_SESSION["username"]){
       echo $_SESSION["username"];
    }else{
       echo "unset";
    }
    ?>我想是否是搂主的php.ini设置有问题啊???我是win2000+apache+php4.3.3
    我的php.ini中关于session的存放路径设的是:session.save_path = D:\php\tmp
    我是在d盘下的php中建了个tmp目录,专门用来存放session,关于session的操作从没出过错误!建议搂主也这样试试!
      

  4.   

    //4.php
    <?
    session_start();
    $name="Alan";
    session_register("name");
    session_name($name);
    header("Location:5.php");
    ?>//5.php
    <?
    session_start();
    print "||";
    if(session_is_registered("name"))
    {
    print "name:".$name;
    }else
    {
    print "name is null";
    }
    ?>需要重新提交4.php一次才可以正确显示,不知是何道理.