dsvq5069 2010-11-07 13:02
浏览 39
已采纳

PHP脚本在线工作,但没有脱机

This script works online but not offline via WAMP...

function current_user()
    {
        static $current_user;
        if(!$current_user)
        {
            if($_SESSION['userID'])
            {
                $userID = intval($_SESSION['userID']);
                $query = "SELECT * 
                          FROM `users`
                          WHERE `id` = $userID";
                $data  = mysql_query($query);
                if(mysql_num_rows($data))
                {
                    $current_user = mysql_fetch_assoc($data);
                    return $current_user;
                }
            }
        }
        return $current_user;
    }

When this function is called, I get the following error message...

Notice: Undefined index: userID in C:\wamp\www\alpha\_includes\session.php on line 38

Line 38 is $userID = intval($_SESSION['userID']);

The error only occurs when the userID SESSION variable isn't set. That and when the function is called via a page from my offline testing computer (running WAMP).


As a side note, this isn't my script. Credit goes to Jim Hoskins of Think Vitamin Membership.

  • 写回答

3条回答 默认 最新

  • duangan6731 2010-11-07 13:07
    关注

    You have notices enabled on one server, but not the other. This notice is just telling you that are attempting to read an array element that doesn't exist.

    Instead, try this

    if(isset($_SESSION['userID']))
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题