从网上搞了个纯php聊天室的代码,不带数据库的,登陆用户名用session记录,为了防止出现同名登陆用户我想写个脚本读取session文件来获取所有当前在线的用户名,
假设某当前登陆用户在服务器上生成的session文件为 B:\TEMP\sess_6a01441ccdf2232d2228dcb101509362,此文件的文本内容为 username|s:4:"zzzz";
运行我的php脚本代码后出现错误提示:
C:\>php.exe -f B:\TEMP\t.php
Warning: array_push(): First argument should be an array in B:\TEMP\t.php on line 14
Array
(
)问题是$arrssid我已经定义成数组了阿为啥还会报错呢请大哥们帮我看看我的脚本到底错在哪了谢谢阿B:\TEMP\t.php如下:
<?php
// php.exe -f B:\TEMP\t.php
$arrssid=Array();
getssid("B:\TEMP\sess_6a01441ccdf2232d2228dcb101509362");
print_r($arrssid);function getssid($ssfile) {
 if (file_exists($ssfile) && preg_match("/sess/",$ssfile)) {
 $file_handle = fopen($ssfile, "r");
 while (!feof($file_handle)) { $line = fgets($file_handle); }
 fclose($file_handle);
         if (preg_match("/^username\|s\:.*?\"\;$/",$line)) {
         $cid = explode("\"", $line);
         array_push($arrssid, htmlspecialchars_decode($cid[1]));
         }
 }
}
?>

解决方案 »

  1.   

    补充:
    PHP Version => 5.2.6
    System => Windows NT 5.2 build 3790
      

  2.   

    函数getssid()里加入 global $arrssid;
      

  3.   

    谢谢laowowo阿...原来Global的作用是在函数体内访问全局变量, 在函数里不Global引入变量的话是不能直接访问函数体外定义的变量的...哦也~~
      

  4.   

    laowowo
    (老窝窝)
    等 级: #2楼 得分:100
    回复于:2010-03-17 19:23:32
    函数getssid()里加入 global $arrssid;