我有一个网页,页面分为3个内容
PHP库/类(PHP包含文件)
"内部图书馆" function FooFunction(){}
<html>
Header Bar (PHP Include File)
Inside "Header Bar" `<li>$Foo -> FooFunction();</li>`
Header (PHP Include File)
...Rest of Webpage...
Footer (PHP Include File)
</html>
由于某种原因,我的页面停止在执行或调用Foo函数的Header Bar处加载。该函数应该像HTML一样回显HTML:
if($User->getUsersName()){
echo '<a href="#">'.$User->getUsersName().'</a>';
} else{
echo '<a href="/login.php?return_url=&ref=net_bar&method=network">log in</a>';
}
在这里编辑更详细的代码:
的index.php
<?php require("engine/network_system.php");
$Network=new Network();
$Network->setSession();
if($Network->isSessionSet()){
$User= new NetworkUser($_SESSION['network_id']);
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<title>Sample</title
</head>
<body>
<div id="pageWrapper" class="wrapper">
<?php
require("includes/normalize.php");
require("includes/network-bar.php");
require("includes/header.php");
?>
</body>
</html>
类(在包含文件网络系统中)
<?php
require("database-classes.php");
class Network {
function __construct(){
$Database= new Database;
$Database->getConnection();
$Database->startConnection();
$this->endConnection=$Database->endConnection();
}
function isSessionSet(){
if(!isset($_SESSION['network_id'])){
return false;
}
return true;
}
function setSession(){
if(!isset($_SESSION)){
session_start();
}
}
}
class NetworkUser {
function __construct($networkId){
$this->networkId=$networkId;
}
// Getters
function getNetworkId(){
return $this->networkId;
}
function getUsersName(){
$queryName=mysql_query("SELECT network_profile.first_name, network_profile.last_name
FROM network_users, network_profile
WHERE network_users.network_id=network_profile.network_id
AND network_users.network_id='$this->networkId'
LIMIT 1");
if(mysql_num_rows($queryName)==1){
$nameInfo=mysql_fetch_array($queryName);
$firstName=$nameInfo['first_name'];
$lastName=$nameInfo['last_name'];
$usersName=$firstName.' '.$lastName;
return $usersName;
} else {
return false;
}
}
function getDisplayName(){
}
private $networkId, $firstName, $lastName;
}
?>
数据库类
<?php
class Database {
public function __construct(){
Private Info That DOES WORK
}
//Connections
public function getConnection(){
if($this->dbconnect_settings == NULL)
return mysql_connect($this->dbhost, $this->dbusername, $this->dbpassword);
else
return $this->dbconnect_settings;
}
public function startConnection(){
if(!$this->getConnection()){
die('Could not connect to database'.mysql_error());
}
else{
mysql_select_db($this->dbdatabase, $this->getConnection());
}
}
public function endConnection(){
if(!($this->getConnection())){
echo -1;
}
else{
mysql_close($this->getConnection());
}
}
private $dbusername, $dbpassword, $dbhost, $dbdatabase, $dbconnect_settings=NULL;
}
/* $test= new Database();
$test->startConnection();
$test->endConnection();*/
?>