我有一個類命名管理器,保存用戶信息:
<?php
global $manager;
class manager
{
private $user = "";
private $pass = "";
private $name = "";
private $displayName = "";
private $email = "";
private $mobile = "";
private $tel = "";
private $post = "";
private $department = "";
private $avatar = "";
public function manager($user,$pass)
{
$this->user = $user;
$this->pass = md5($pass);
$GLOBALS["manager"] = $this;
}
public function Login()
{
$GLOBALS["DataBase"]->query("select * from ".$GLOBALS["tbPrefix"]."managers where ma_username=N'".$this->user."' and ma_password=N'".$this->pass."'");
if($GLOBALS["DataBase"]->numRows() > 0)
{
$ma = $GLOBALS["DataBase"]->fetchAssoc();
$this->name = $ma["ma_name"];
$this->displayName = $ma["ma_displayname"];
$this->email = $ma["ma_email"];
$this->mobile = $ma["ma_mobile"];
$this->tel = $ma["ma_tel"];
$this->post = $ma["ma_post"];
$this->department = $ma["ma_department"];
$this->avatar = $ma["ma_avatar"];
return true;
}
else
{
return false;
}
}
public function the_manager()
{
return array("username" => $this->user,"name" => $this->name,"displayname" => $this->displayName,"email" => $this->email,"mobile" => $this->mobile,"tel" => $this->tel,"post" => $this->post, "department" => $this->department,"photo" => $this->avatar);
}
}
function get_admin()
{
if($GLOBALS["manager"] != null){
return $GLOBALS["manager"]->the_manager();
}
}
function the_admin_name()
{
if($GLOBALS["manager"] != null){
$info = $GLOBALS["manager"]->the_manager();
echo $info["name"];
}
}
和一個名爲adminController類:
class adminController
{
public function Start()
{
session_start();
$message = "";
if(isset($_POST["username"]) && isset($_POST["password"]))
{
$username = mysql_real_escape_string($_POST["username"]);
$password = mysql_real_escape_string($_POST["password"]);
if(empty($username) or empty($password))
{
$message = "اطلاعات وارد شده معتبر نمی باشد.";
}
else
{
new manager($_POST["username"],$_POST["password"]);
if($GLOBALS["manager"]->Login())
{
$_SESSION["ulogin"] = $username;
header("Location: ".$GLOBALS["sitepath"]["url"]."/admin/manage");
}
else
{
$message = "نام کاربری یا کلمه عبور اشتباه می باشد!";
}
}
}
if(!isset($_SESSION["ulogin"]) && empty($_SESSION["ulogin"]))
require_once($GLOBALS["sitepath"]["root"].'/protected/model/login.php');
else
{
switch($GLOBALS["Action"])
{
case "manage":
if(isset($_SESSION["ulogin"]) && !empty($_SESSION["ulogin"]))
require_once($GLOBALS["sitepath"]["root"].'/protected/model/admin.php');
else
header("Location: ".$GLOBALS["sitepath"]["url"]."/admin");
break;
case "logout":
session_destroy();
session_unset();
header("Location: ".$GLOBALS["sitepath"]["url"]."/admin");
break;
case "uploader":
if(isset($_GET['method']))
{
switch($_GET['method'])
{
case 'upload':
require_once(blog("root").'/protected/model/handleupload.php');
break;
case 'get':
require_once(blog("root").'/protected/model/panelfiles.php');
break;
case 'info':
require_once(blog("root").'/protected/model/fileinfo.php');
break;
case 'delete':
require_once(blog("root").'/protected/model/deletefile.php');
break;
default:
throw new Exception('404');
break;
}
}
else
{
throw new Exception('404');
}
break;
default:
if(isset($_SESSION["ulogin"]) && !empty($_SESSION["ulogin"]))
header("Location: ".$GLOBALS["sitepath"]["url"]."/admin/manage");
else
require_once($GLOBALS["sitepath"]["root"].'/protected/model/login.php');
break;
}
}
}
}
和文件的login.php命名。
在經理類中我有$ GLOBALS變量名爲「經理」,用於admin.php與函數「the_admin_name()」。
這個函數調用$ GLOBALS [ 「經理人」],但其空和錯誤:
致命錯誤:調用一個成員函數the_manager(d)中一個非對象:\ XAMPP \ htdocs中\ Rastak \ protected \ model \ functions \ manager.class.php on line 64
您意識到'havePosts'返回一個布爾值,它不能被回顯? – wavemode 2014-09-28 05:45:48