php-PHP中include后,函数中需要global部分变量
程序员文章站
2022-06-16 08:37:06
...
php
PHP中include后,部分函数中需要global部分变量,例如下面global $db;问,如果不用global,怎么完美解决
/*
- 功能:检测用户登录
- 参数:
- 返回:boolen/function check_login() {if(isset($_SESSION['shell'])==false) return false;* global $db;**$uid = $_SESSION['uid'];$rel = $db->findall('members', "WHERE
uid
='" . $uid . "'");while ($row = $db->fetch_array($rel)) { foreach ($row as $key => $value) { $uinfo[$key] = $value; }}$ushell = md5($uinfo['password'] . $uinfo['role'] . DSLOG_ENC);if ($ushell == $_SESSION['shell']) { return true;} else { return false;}}?>