PHP脚本可以在线工作,但不能脱机(PHP script works online but no offline)

编程入门 行业动态 更新时间:2024-10-26 06:36:39
PHP脚本可以在线工作,但不能脱机(PHP script works online but no offline)

此脚本在线工作,但不通过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; }

当这个函数被调用时,我得到以下错误信息...

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

第38行是$userID = intval($_SESSION['userID']);

只有在未设置userID SESSION变量时才会出现该错误。 该功能通过离线测试计算机(运行WAMP)的页面调用。


作为一个侧面说明,这不是我的脚本。 信用归因于Think Vitamin Membership的Jim Hoskins。

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.

最满意答案

您在一台服务器上启用了通知,但没有启用另一台服务器。 本通知只是告诉你正试图读取一个不存在的数组元素。

相反,试试这个

if(isset($_SESSION['userID']))

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']))

更多推荐

本文发布于:2023-07-28 01:18:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1298314.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:在线   脚本   工作   PHP   offline

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!