【问题标题】:HTTP ERROR 500 - phpHTTP 错误 500 - php
【发布时间】:2020-09-24 17:26:58
【问题描述】:

我正在尝试打开 index.php 页面,但浏览器显示此错误: 目前无法处理此请求。 HTTP 错误 500

我不认为错误出现在 config.php 页面上,因为数据库配置适用于 index.php 以外的页面

这是我的 index.php 代码:

<?php 
    require_once 'config.php'; 

    login_required(); 
    $users = count_query("SELECT COUNT(*) AS num FROM users"); 
    $emails = count_query("SELECT COUNT(*) AS num FROM subscribers"); 
    $subs = count_query("SELECT COUNT(*) AS num FROM subscriptions"); 
    $nls = count_query("SELECT COUNT(*) AS num FROM newsletters"); 
    $mess = count_query("SELECT COUNT(*) AS num FROM messages"); 
    $temps = count_query("SELECT COUNT(*) AS num FROM templates"); 
    $title = "Home!"; 
    $content = <<<EOF 
    <h3>current stats</h3> 
    <p>$users user registered</p> 
    <p>$emails subscribers</p> 
    <p>$subs newsletter subscriptions</p> 
    <p>$nls newsletters</p> 
    <p>$mess messages</p> 
    <p>$temps templates</p> 
    EOF; 
    include 'layout.php'; ?>

布局页面:

 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> 
    <html xmlns="http://www.w3.org/1999/xhtml" > 
        <head> 
            <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 

            <title><?php echo $title; ?> » my newsletter app</title> 
            <!-- Stylesheets --> 
            <!-- <link rel="stylesheet" href="media/style.css" type="text/css" media="all" /> --> 
        </head> 
        <body<?php if ($mini == true) { ?> class="mini"<?php } ?>> 
            <div id="header"> 
                <h1><a href="index.php">my newsletter app</a></h1> 
            </div> 
            <?php if ($nonav == false) { ?> 
            <div id="nav"> 
                <a href="messages.php"<?php if($tab == 'mess') {?>class="current"<?php } ?>>messages</a> 
                <a href="subscribers.php"<?php if($tab == 'sub') {?>class="current"<?php } ?>>subscribers</a> 
                <a href="newsletters.php"<?php if($tab == 'nl') {?>class="current"<?php } ?>>newsletters</a> 
                <a href="templates.php"<?php if($tab == 'temp') {?>class="current"<?php } ?>>templates</a> 
                <span class="right"> 
                    <a href="logout.php">log out</a> 
                </span> 
            </div> 
            <?php } ?> 
            <div id="container"> 
                <h3><?php echo $title;?></h3> 
                <?php echo $content; ?> 
            </div> 
        </body> 
    </html>

配置页面:

<?php  
    // DB Settings 
    define('DB_SERVER', 'localhost'); 
    define('DB_USER', 'abdulsme_admin'); 
    define('DB_PASSWORD', 'bypass'); 
    define('DB_NAME', 'abdulsme_newsletter'); 

    define('FROM_EMAIL', 'no_reply@ohyeahemail.com'); 
    define('FROM_NAME', 'oh yeah email!'); 


    session_start(); 
    require_once 'classes.php'; 
    $mini = false; 
    $nonav = false; 
    error_reporting(0);
    ?>

【问题讨论】:

  • 如果你删除所有代码,只写你好呢?
  • 只写你好就可以了
  • 查看服务器日志,让我们知道,以便我们为您提供帮助:)
  • 太棒了!!您逐步检查以确定错误的确切位置。 1.通过添加configphp 2.添加索引页面代码的其余部分3.并通过添加layout.php
  • 如何查看服务器日志?

标签: php


【解决方案1】:

从结束的 EOF 中删除所有缩进;行。

来自 PHP 手册:

请务必注意,带有结束标识符的行不能包含其他字符,分号 (;) 除外。这尤其意味着标识符不能缩进,分号前后不能有任何空格或制表符。

如果这个规则被破坏并且关闭标识符不是“干净的”,它将不会被认为是一个关闭标识符,PHP 将继续寻找一个。如果在当前文件结尾之前没有找到合适的结束标识符,则会在最后一行出现解析错误。

http://php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc

【讨论】:

    【解决方案2】:

    更改:

    $content = <<<EOF 
    <h3>current stats</h3> 
    <p>$users user registered</p> 
    <p>$emails subscribers</p> 
    <p>$subs newsletter subscriptions</p> 
    <p>$nls newsletters</p> 
    <p>$mess messages</p> 
    <p>$temps templates</p> 
    EOF;
    

    收件人:

    $content = "
    <h3>current stats</h3> 
    <p>$users user registered</p> 
    <p>$emails subscribers</p> 
    <p>$subs newsletter subscriptions</p> 
    <p>$nls newsletters</p> 
    <p>$mess messages</p> 
    <p>$temps templates</p> 
    ";
    

    或至:

    $content = <<<EOF
        <h3>current stats</h3> 
        <p>$users user registered</p> 
        <p>$emails subscribers</p> 
        <p>$subs newsletter subscriptions</p> 
        <p>$nls newsletters</p> 
        <p>$mess messages</p> 
        <p>$temps templates</p> 
    EOF;
    

    【讨论】:

    • 请在您的答案中添加一些解释,以便其他人可以从中学习。为什么此更改有助于解决服务器错误?
    猜你喜欢
    • 1970-01-01
    • 2018-02-28
    • 1970-01-01
    • 2011-01-14
    • 2018-03-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多