设置php.ini中的
register_globals = On
默认情况下是off的,因此不能使用$username,改成on以后就可以用了。

解决方案 »

  1.   

    主机商那边是off的,呵呵,改那个没有根本解决
    根本的解决是修改代码,声明全局变量
      

  2.   

    可以了,,但是又有新问题,设置cookie时接收不到值,我的程序是:<FORM action=login.php method=post name=login>
    用户名:
    <input name="username" size="15">
    密码:
    <input name="password" type=password size="15">
    <input name="button1" type=submit value=" 登 录 ">
    </form>login.php<?
    include ("oracle.inc");
    $userid=""; $groupid="";
    $a=new db;
    $sqlstr="select ui,un,gi from users";
    $a->query($sqlstr);
    while($a->next_record()){
    $userid=$a->Record["ui"];
    $username=$a->Record["un"];
    $groupid=$a->Record["gi"];
    }
    setcookie("cookie_username",$username);
    setcookie("cookie_userid",$userid);
    setcookie("cookie_groupid",$groupid);
    ?>
    <html>
    <head>
    <title></title>
    <script language="Javascript">
    function goto_next(){ document.form1.submit();
    }
    </script>
    </head>
    <body onload="Javascript:goto_next();">
    <form name="form1" action="t2.php" method="post" target="_top">
    </form>
    </body>
    </html>//数据库连接成功;可以打印出$userid,$username,$groupid
    t2.php
    <?
    define("cookie_un",$HTTP_COOKIE_VARS["cookie_username"]);
    define("cookie_ui",$HTTP_COOKIE_VARS["cookie_userid"]);
    define("cookie_gi",$HTTP_COOKIE_VARS["cookie_groupid"]);
    echo cookie_un;
    echo cookie_ui;
    echo cookie_gi;
    ?>
    //有时候可以打印出cooki_gi,,但其他两个死活打印不出来。
    这是为什么?php3转成php4下执行,,有哪些地方需要注意的,php.ini中,哪些要
    重配置?
    送高分,,不过再加。
      

  3.   

    直接echo $HTTP_COOKIE_VARS["cookie_username"]."<br>".$HTTP_COOKIE_VARS["cookie_groupid"]看看。还有就是检查一下你在设cookie的时候是否确实有值
      

  4.   

    $_GET[]
    $_POST[]
    $_SESSION[]
    $_COOKIE[]
      

  5.   

    直接echo $HTTP_COOKIE_VARS["cookie_username"]时可以打印出值来,,cookie有值的,
    而且用_cookie[]也不行,,