I am running a site right now on network solutions small unix server. This is my clients choice, not mine. Lets assume changing is not an option right now.
I am getting a high number of 500 internal server error occurrences. They are sporadic, but clearly happening way too often. There isn't much consistency to what pages trigger the error but it is happening too much and it is very frustrating.
In terms of setting up servers and messing around with settings...well, I don't have much experience with that type of thing...usually what I do works.
Okay I have enabled errors and here is what I received:
[Wed Dec 14 23:56:04 2011][error] [client *] Premature end of script headers: index.php, referer: mysite.com/administration/
Here is my code for that page:
<?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");
?>
And here is utilities/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.';
}
}
The error 500 is too general and it is impossible to extract any significant information out of it.
And it is a web-server's error message.
While for the reason of this error you have to get the PHP error message somewhere.
It is usually logged in the web-server error log.
Thus, you have to peek to the server's error log to make yourself enlightened of the certain cause of the problem.
Note to the zealous moderators: This is the answer. The only possible answer to the "I am getting 500 error" question.
Now, to the edited part of the question.
This is still insufficient error message and still from the web-server part.
And you still need to have the PHP error message. Means PHP just died without any output. But it have to issue an error message on the cause.
Make sure you have errors raised and logged.
check phpinfo()
output for the error_reporting
(should be non-zero), 'log_errors' and error_log
parts, and correct them accordingly.