作为 require_once 附加 MySQL 服务器连接的问题
当我输入直接 URL 来访问网站上保存数据库连接的页面 db_connect.php 时,它会返回一条成功消息。当我在我的主标题页上需要它一次来确定向网站访问者显示什么内容时(即,如果他们登录,它将显示一组链接。如果没有,它将显示一组不同的链接),它突然决定出错并杀死页面上其余的 PHP 代码。当我摆脱链接到数据库连接的 require_once 时,所有 PHP 都工作正常。我什至尝试过使用相对 URL。我将尝试最后一件事,但只是想获得对此的意见。我的猜测是我无法将数据库连接存储在文件夹中。
<?php
require_once("account-management/db_connect.php");
session_start();
if (isset($_SESSION['user_lister_id']) && ($_SESSION['email'])) {
echo '<section class="topnavbar">';
echo '<div id="top-login">';
echo '<a href="#">Listing Profile</a> / <a href="#">Account Settings</a> / <a href="#">Case Requests</a>';
echo '</div>';
echo '</section>';
} else {
echo '<section class="topnavbar">';
echo '<div id="top-register">';
echo '<a href="#">Client Register</a> / <a href="#">Lister Register</a>';
echo '</div>';
echo '<div id="top-login">';
echo '<a href="#">Client Login</a> / <a href="#">Lister Login</a>';
echo '</div>';
echo '</section>';
}
?>
<section class="header-grid">
<img src="../images/Logo.png" width="120" />
<div id="ad-field">This content coming soon!</div>
</section>
When I type in the direct URL to access the page that holds the database connection, db_connect.php on the website, it brings back a message of being successful. When I require it once on my master header page to determine what to show the website visitor (ie. if they're logged in it will show a set of links. If not, it will show a different set) it suddenly decides to error out and kills the rest of the PHP on the page. When I get rid of the require_once that links to the DB connection, all the PHP works fine. I've even tried using a relative URL. I am going to try one last thing but just wanted to get input on this. My guess is that I can't store the database connection in a folder.
<?php
require_once("account-management/db_connect.php");
session_start();
if (isset($_SESSION['user_lister_id']) && ($_SESSION['email'])) {
echo '<section class="topnavbar">';
echo '<div id="top-login">';
echo '<a href="#">Listing Profile</a> / <a href="#">Account Settings</a> / <a href="#">Case Requests</a>';
echo '</div>';
echo '</section>';
} else {
echo '<section class="topnavbar">';
echo '<div id="top-register">';
echo '<a href="#">Client Register</a> / <a href="#">Lister Register</a>';
echo '</div>';
echo '<div id="top-login">';
echo '<a href="#">Client Login</a> / <a href="#">Lister Login</a>';
echo '</div>';
echo '</section>';
}
?>
<section class="header-grid">
<img src="../images/Logo.png" width="120" />
<div id="ad-field">This content coming soon!</div>
</section>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论