此脚本在线工作,但不通过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 38Line 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']))更多推荐
发布评论