【问题标题】:How do I end 500 internal server error? Most of my code is PHP如何结束 500 内部服务器错误?我的大部分代码是 PHP
【发布时间】:2012-01-20 20:15:25
【问题描述】:

我现在在网络解决方案小型 unix 服务器上运行一个站点。这是我客户的选择,不是我的。让我们假设现在改变不是一种选择。

我收到大量 500 次内部服务器错误事件。它们是零星的,但显然发生得太频繁了。哪些页面触发了错误并没有太大的一致性,但它发生的太多了,非常令人沮丧。

在设置服务器和搞乱设置方面......好吧,我对这类事情没有太多经验......通常我所做的工作。

好的,我已启用错误,这是我收到的内容:

[Wed Dec 14 23:56:04 2011][error] [client *] 脚本头提前结束:index.php,引用:mysite.com/administration/

这是我的页面代码:

<?php
//start the session
session_start();
if (isset($_SESSION['user_id'])) {
      header('Location:main.php');
}
else{


include("../includes/configure.php");
$menu_bar = false;
$login_form = true;
$status = 'Please Log in';
$header_message = 'Welcome to the mysite Administartion System';

if (isset($_POST['submit'])) {

include("utilities/login.php");

}

if (isset($_GET['redirect'])){

    switch ($_GET['redirect']) {

            case 'denied':
            $header_message = 'The page you have tried to access is forbidden, please login';
            break;

            case 'logout':
            $header_message = 'You have logged out successfully';


    }
  }
}

include($layout_includes_dir."header.php");
include($admin_layout_dir."administration_layout.php");
include($layout_includes_dir."footer.php");




?>

这里是实用程序/login.php

if (!isset($_SESSION['user_id'])) {


     $username = mysqli_real_escape_string($dbc, trim($_POST['username']));
     $password = mysqli_real_escape_string($dbc, trim($_POST['password']));


      if (!empty($username) && !empty($password)) {
        // Look up the username and password in the database
        $query = "SELECT id, username, password FROM user WHERE username = '$username' AND password = SHA('$password')";
        $data = mysqli_query($dbc, $query);

          if (mysqli_num_rows($data) == 1) {
          // The log-in is OK so set the user ID and username session vars (and cookies), and redirect to the home page
          $row = mysqli_fetch_array($data);

          $_SESSION['user_id'] = $row['id'];
          $_SESSION['username'] = $row['username'];


          header('Location:main.php');
          }
          else{
          // The username/password are incorrect so set an error message
          $message = 'Sorry, you must enter a valid username and password to log in.';
          }

        }
         else {
        // The username/password weren't entered so set an error message
          $message = 'Please enter a username or password to login.';
         }
     }

【问题讨论】:

  • 查看error.log 或系统日志以找到更具体的提示。其他一切都只是猜测。另外你真的有一个原始的 CGI 版本的 PHP 运行吗?作为 .cgi 文件之类的脚本?
  • 错误 500 通常意味着您的 PHP 应用程序出现错误,如果您使用 php 文件内容和日志文件编辑问题,也许我们可以尝试帮助诊断原因问题
  • 好的,发现错误信息并添加到原始问题中!
  • 这可能与您的问题无关,但您应该知道发送 Location 标头不会结束脚本。也就是说,仍然会向客户端发送页面(例如,最后的所有includes),但大多数人不会看到它,因为浏览器透明地遵循重定向。

标签: php apache


【解决方案1】:

错误 500 过于笼统,无法从中提取任何重要信息。
这是一个网络服务器的错误信息。
由于此错误,您必须在某处获得 PHP 错误消息
它通常记录在网络服务器错误日志中。
因此,您必须查看服务器的错误日志以了解问题的某些原因。

热心的版主请注意:这就是答案。 “我收到 500 错误”问题的唯一可能的答案

现在,进入问题的已编辑部分。
这仍然是错误消息不足,仍然来自网络服务器部分。
而且您仍然需要有 PHP 错误消息。意味着 PHP 在没有任何输出的情况下就死了。但它必须针对原因发出错误消息。
确保您提出并记录了错误。
检查phpinfo() 输出中的error_reporting(应该是非零)、'log_errors' 和error_log 部分,并相应地更正它们。

【讨论】:

  • display_errors 为“on” error_reporting 为“no value” log_errors 为“off”且 error_log 为“no value”,因此根据该信息,我是否需要更改其中的任何一个,如果是,我该怎么做在共享主机上执行此操作?我可以简单地修改 php.ini 还是有别的?
猜你喜欢
  • 1970-01-01
  • 2017-09-03
  • 2014-06-08
  • 2018-01-15
  • 2010-12-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多