gpt4 book ai didi

php - 无法在另一个 php 文件中添加 navigation.php

转载 作者:行者123 更新时间:2023-11-29 07:52:14 25 4
gpt4 key购买 nike

显示一个 fatal error :无法在第 13 行/home/web/public_html/loginfinal/include/database.php 中重新声明类 MySQLDB当我使用下面的代码时。

<?php $site_root = $_SERVER['DOCUMENT_ROOT']; ?>
<?
include("include/session.php");
if(!$session->isVerified() && $session->logged_in){
header("Location: email.php");
}
?>

<html>
<title>Login page</title>
<body>

<?php
include_once($site_root ."/loginfinal/nav_top.php");
?>
<table>
<tr>
<td>
<?
//others detail
?>

读完这个问题后,现在我使用下面的代码,它不显示任何错误,也不显示导航。请问我的问题出在哪里?

<?php $site_root = $_SERVER['DOCUMENT_ROOT']; ?>
<?
include("include/session.php");
if(!$session->isVerified() && $session->logged_in){
header("Location: email.php");
?>

<html>
<title>Login page</title>
<body>

<?php
if(!class_exists('MySQLDB') == true){
include_once($site_root ."/loginfinal/nav_top.php");}
?>
<table>
<tr>
<td>
<?
//others detail
?>

这是我的 Nnav_top.php

<?
include("include/session.php");
include("db.php");
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">

<head>
<META name="TITLE" content="navigation">
<meta name="viewport" content="width=device-width,initial-scale=1">
<meta http-equiv='Content-Type' content='text/html; charset=UFT-8'/>
<title>navigation</title>

<link rel="stylesheet" href="/css/bootstrap.min.css">
<link rel="stylesheet" href="/css/bootstrap-theme.min.css">
<script src="/js/jquery.min.js"></script>
<script src="/js/bootstrap.min.js"></script>

</head>
<body>
<nav role="navigation" class="navbar navbar-inverse">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="container">
<div class="navbar-header">
<button type="button" data-target="#navbarCollapse" data-toggle="collapse" class="navbar-toggle">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a href="#" class="navbar-brand"><img src="image.jpg" width="55" height="40">BD Showbiz</a>
</div>
<!-- Collection of nav links, forms, and other content for toggling -->
<div id="navbarCollapse" class="collapse navbar-collapse">
<ul class="nav navbar-nav">
<li class="active"><a href="#"><span class="glyphicon glyphicon-home"></span> <br>Home</a></li>
<li><a href="/bd_About%20Us.htm"><span class="glyphicon glyphicon-heart"></span> <br>About Us</a></li>
<li class="dropdown">
<a data-toggle="dropdown" class="dropdown-toggle" href="#"><span class="glyphicon glyphicon-shopping-cart"></span> <br>Service<b class="caret"></b></a>
<ul role="menu" class="dropdown-menu">
<li class="dropdown-submenu"> <a href="#">Event Management</a>
<ul class="dropdown-menu">
<li><a href="/bd_Corporate%20Event.htm">Corporate Event</a></li>
<li><a href="/wedding.htm">Wedding Event</a></li>
<li><a href="/bd_Others%20Event.htm">Others Privet Event</a></li>
</ul>
</li>
<li><a href="/bd_Offer.htm">Special Offer</a></li>
</ul>
</li>
<li class="dropdown">
<a data-toggle="dropdown" class="dropdown-toggle" href="#"><span class="glyphicon glyphicon-th-large"></span> <br>Web Service<b class="caret"></b></a>
</li>
<li><a href="/bd_contact_us.php"><span class="glyphicon glyphicon-map- marker"></span> <br>Contact Us</a></li>
</ul>

<form role="search" class="navbar-form navbar-left" method="get" action="/search.htm"><span class="glyphicon glyphicon-search"></span> <br>
<div class="form-group">
<input type="text" placeholder="Search" id="tfq" class="form-control" name="q">
<input type="hidden" name="sitesearch" value="" />
<input type="hidden" name="sitesearch" value="" checked />
</div>
</form>
<ul class="nav navbar-nav">
<?php
if($session->logged_in){
echo '<a data-toggle="dropdown" class="dropdown-toggle" href="#" id="navLogin"><span class="glyphicon glyphicon-user"></span> <br>'.$session->username.' <b class="caret"></b> </a>';
echo ' <ul role="menu" class="dropdown-menu">';
echo ' <li><a href=/main.php>Profile</a></li>';
echo ' <li><a href=/useredit.php>Setting</a></li>';
echo ' <li class="divider"></li>';
if($session->isAdmin()){
echo '<li><a href=/admin/admin.php>Admin Center</a></li>';
}
echo ' <li><a href=process.php>Logout</a></li>';
echo ' </ul>';
}else{
echo '<a data-toggle="dropdown" class="dropdown-toggle" href="#" id="navLogin"><span class="glyphicon glyphicon-log-in"></span> <br>login <b class="caret"></b></a>';
echo ' <ul role="menu" class="dropdown-menu">';
echo ' <form style="margin: 0px" accept-charset="UTF-8" action="process.php" method="post">';

echo ' </form>';
echo ' </ul>';
}
?>
<li class="divider-vertical"></li>
<?php
global $dbh;
//Check image address
$result2 = mysqli_query($dbh,"SELECT u_imgurl FROM blog_users WHERE username='$session- >username'");
if(!$result2) {
die("Database query failed: " . mysqli_error());
}
$u_imgurl = "";
while ($row = mysqli_fetch_array($result2)) {
$u_imgurl = $row["u_imgurl"];
}
if (empty($u_imgurl)) $u_imgurl = "picture.jpg";
//End Check image address
if($session->logged_in){
echo '<li><img alt="" src="/loginfinal/img/'.$u_imgurl.'" width="40" height="40" class="img-responsive img-circle profile-img"/></li>';
}else{
echo '<li><a href="/loginfinal/register.php"><span class="glyphicon glyphicon-lock"> </span> <br>Sign Up</a></li>';
}
?>

</li>
</ul>
</div>
</div>
</nav>
</body>
</html>

我的数据库.php

<?
/**
* Database.php
*
* The Database class is meant to simplify the task of accessing
* information from the website's database.
*
*
*/
include("constants.php");

class MySQLDB
{
var $connection; //The MySQL database connection
var $num_active_users; //Number of active users viewing site
var $num_active_guests; //Number of active guests viewing site
var $num_members; //Number of signed-up users
/* Note: call getNumMembers() to access $num_members! */

/* Class constructor */
function MySQLDB(){
/* Make connection to database */
$this->connection = mysql_connect(DB_SERVER, DB_USER, DB_PASS) or die(mysql_error());
mysql_select_db(DB_NAME, $this->connection) or die(mysql_error());

/**
* Only query database to find out number of members
* when getNumMembers() is called for the first time,
* until then, default value set.
*/
$this->num_members = -1;

if(TRACK_VISITORS){
/* Calculate number of users at site */
$this->calcNumActiveUsers();

/* Calculate number of guests at site */
$this->calcNumActiveGuests();
}
}

function confirmUserPass($username, $password){
/* Add slashes if necessary (for query) */
if(!get_magic_quotes_gpc()) {
$username = addslashes($username);
}

/* Verify that user is in database */
$q = "SELECT password FROM ".TBL_USERS." WHERE username = '$username'";
$result = mysql_query($q, $this->connection);
if(!$result || (mysql_numrows($result) < 1)){
return 1; //Indicates username failure
}

/* Retrieve password from result, strip slashes */
$dbarray = mysql_fetch_array($result);
$dbarray['password'] = stripslashes($dbarray['password']);
$password = stripslashes($password);

/* Validate that password is correct */
if($password == $dbarray['password']){
return 0; //Success! Username and password confirmed
}
else{
return 2; //Indicates password failure
}
}

function confirmUserID($username, $userid){
/* Add slashes if necessary (for query) */
if(!get_magic_quotes_gpc()) {
$username = addslashes($username);
}

/* Verify that user is in database */
$q = "SELECT userid FROM ".TBL_USERS." WHERE username = '$username'";
$result = mysql_query($q, $this->connection);
if(!$result || (mysql_numrows($result) < 1)){
return 1; //Indicates username failure
}

/* Retrieve userid from result, strip slashes */
$dbarray = mysql_fetch_array($result);
$dbarray['userid'] = stripslashes($dbarray['userid']);
$userid = stripslashes($userid);

/* Validate that userid is correct */
if($userid == $dbarray['userid']){
return 0; //Success! Username and userid confirmed
}
else{
return 2; //Indicates userid invalid
}
}

function usernameTaken($username){
if(!get_magic_quotes_gpc()){
$username = addslashes($username);
}
$q = "SELECT username FROM ".TBL_USERS." WHERE username = '$username'";
$result = mysql_query($q, $this->connection);
return (mysql_numrows($result) > 0);
}

function usernameBanned($username){
if(!get_magic_quotes_gpc()){
$username = addslashes($username);
}
$q = "SELECT username FROM ".TBL_BANNED_USERS." WHERE username = '$username'";
$result = mysql_query($q, $this->connection);
return (mysql_numrows($result) > 0);
}

function addNewUser($username, $password, $email, $emailvcode){
$time = time();
/* If admin sign up, give admin user level */
if(strcasecmp($username, ADMIN_NAME) == 0){
$ulevel = ADMIN_LEVEL;
$verifystatus = 0;
}else{
$ulevel = USER_LEVEL;
$verifystatus = 0;
}
$q = "INSERT INTO ".TBL_USERS." VALUES ('$username', '$password', '0', $ulevel, '$email', '$verifystatus', '$emailvcode', '$time')";
return mysql_query($q, $this->connection);
}

function updateUserField($username, $field, $value){
$q = "UPDATE ".TBL_USERS." SET ".$field." = '$value' WHERE username = '$username'";
return mysql_query($q, $this->connection);
}

function getUserInfo($username){
$q = "SELECT * FROM ".TBL_USERS." WHERE username = '$username'";
$result = mysql_query($q, $this->connection);
/* Error occurred, return given name by default */
if(!$result || (mysql_numrows($result) < 1)){
return NULL;
}
/* Return result array */
$dbarray = mysql_fetch_array($result);
return $dbarray;
}

/**
* retrieve email verification code
*/
function emailVerify($vcode){
$q = "SELECT * FROM ".TBL_USERS." WHERE emailverifier = '$vcode'";
$result = mysql_query($q, $this->connection);
/* Verification code exists, verify user and return true */
if(mysql_num_rows($result) != 0){
$q = "UPDATE ".TBL_USERS." SET verifystatus = '1' WHERE emailverifier = '$vcode'";
$result = mysql_query($q, $this->connection);
return 1;
}
/* verification code doesn't exist return false */
else
{
return 0;
}
}

function getNumMembers(){
if($this->num_members < 0){
$q = "SELECT * FROM ".TBL_USERS;
$result = mysql_query($q, $this->connection);
$this->num_members = mysql_numrows($result);
}
return $this->num_members;
}

function calcNumActiveUsers(){
/* Calculate number of users at site */
$q = "SELECT * FROM ".TBL_ACTIVE_USERS;
$result = mysql_query($q, $this->connection);
$this->num_active_users = mysql_numrows($result);
}

function calcNumActiveGuests(){
/* Calculate number of guests at site */
$q = "SELECT * FROM ".TBL_ACTIVE_GUESTS;
$result = mysql_query($q, $this->connection);
$this->num_active_guests = mysql_numrows($result);
}

function addActiveUser($username, $time){
$q = "UPDATE ".TBL_USERS." SET timestamp = '$time' WHERE username = '$username'";
mysql_query($q, $this->connection);

if(!TRACK_VISITORS) return;
$q = "REPLACE INTO ".TBL_ACTIVE_USERS." VALUES ('$username', '$time')";
mysql_query($q, $this->connection);
$this->calcNumActiveUsers();
}

/* addActiveGuest - Adds guest to active guests table */
function addActiveGuest($ip, $time){
if(!TRACK_VISITORS) return;
$q = "REPLACE INTO ".TBL_ACTIVE_GUESTS." VALUES ('$ip', '$time')";
mysql_query($q, $this->connection);
$this->calcNumActiveGuests();
}

/* These functions are self explanatory, no need for comments */

/* removeActiveUser */
function removeActiveUser($username){
if(!TRACK_VISITORS) return;
$q = "DELETE FROM ".TBL_ACTIVE_USERS." WHERE username = '$username'";
mysql_query($q, $this->connection);
$this->calcNumActiveUsers();
}

/* removeActiveGuest */
function removeActiveGuest($ip){
if(!TRACK_VISITORS) return;
$q = "DELETE FROM ".TBL_ACTIVE_GUESTS." WHERE ip = '$ip'";
mysql_query($q, $this->connection);
$this->calcNumActiveGuests();
}

/* removeInactiveUsers */
function removeInactiveUsers(){
if(!TRACK_VISITORS) return;
$timeout = time()-USER_TIMEOUT*60;
$q = "DELETE FROM ".TBL_ACTIVE_USERS." WHERE timestamp < $timeout";
mysql_query($q, $this->connection);
$this->calcNumActiveUsers();
}

/* removeInactiveGuests */
function removeInactiveGuests(){
if(!TRACK_VISITORS) return;
$timeout = time()-GUEST_TIMEOUT*60;
$q = "DELETE FROM ".TBL_ACTIVE_GUESTS." WHERE timestamp < $timeout";
mysql_query($q, $this->connection);
$this->calcNumActiveGuests();
}

function query($query){
return mysql_query($query, $this->connection);
}
};
$database = new MySQLDB;
?>

最佳答案

它不会显示,因为您正在检查该类是否不存在(事实确实如此),因为它提示它被重新声明(重新创建)。

  • 将所有出现的 include/require 更改为 include_once/require_once

这将使文件仅在请求中包含一次,这意味着该类不会重新声明。

关于php - 无法在另一个 php 文件中添加 navigation.php,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26118959/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com