Web Hosting Talk







View Full Version : PHP Include, Internal Server Error


killrwhale
05-12-2009, 06:08 PM
Hello,

I was running a php script that had a php include for a login script on the same page. Then out of nowhere after months of working, it stopped working. When I would try to access to page, I would get an INTERNAL SERVER ERROR.

So I contacted my host, and they told me there were these errors:

[Mon May 11 14:53:55 2009] [error] [client 121.247.154.49] Premature end of script headers: index.php
The following errors where obtained from the custom log /home/public_html/error_log.
[11-May-2009 14:44:32] PHP Notice: Undefined offset: 3 in /home/public_html/script.php on line 91
[11-May-2009 14:44:32] PHP Notice: Undefined offset: 1 in /home/public_html/script.php on line 92
[11-May-2009 14:44:32] PHP Notice: Undefined offset: 2 in /home/public_html/script.php on line 93


So I went into my script and removed a simple line of code:

<?
include "../login/login.php";
?>


After removing that, it loaded fine. But everytime I add it, it does not load and gives me an Internal Server Error.

My question is, what could cause this to suddenly happen? Also, this is the code after the php code above:

<?php
require_once("functions.php");
ini_set("display_errors", "Off");
error_reporting(0);
...etc etc


Am I not able to have 2 includes/requires in one php script? Or is it something wrong with the login.php?

Thank You

DNGeeks
05-12-2009, 06:30 PM
It's quite possible your host has updated PHP and now no longer allows short_open_tags.

Try changing <? to <?php and see how it goes.

killrwhale
05-12-2009, 06:32 PM
It's quite possible your host has updated PHP and now no longer allows short_open_tags.

Try changing <? to <?php and see how it goes.

Yea, I was thinking that. But I asked the hosting, they said they did no changes. I also tried that, and it did not work :(

allportpc
05-12-2009, 09:39 PM
at the very top of you page, try adding <?php ob_start(); ?>. Make sure this is the first line executed.

csparks
05-12-2009, 09:58 PM
These are of concern, but I dont think they should prevent the file from including:

[11-May-2009 14:44:32] PHP Notice: Undefined offset: 3 in /home/public_html/script.php on line 91
[11-May-2009 14:44:32] PHP Notice: Undefined offset: 1 in /home/public_html/script.php on line 92
[11-May-2009 14:44:32] PHP Notice: Undefined offset: 2 in /home/public_html/script.php on line 93

Basically you have array elemnts that are expected to be defined, but are not. The script is not checking to ensure they are defined before calling them.

what does those lines call, and whats before and after the lines? Usually a internal server error is a permission problem I think.

killrwhale
05-12-2009, 11:56 PM
at the very top of you page, try adding <?php ob_start(); ?>. Make sure this is the first line executed.

Hey, I tried that. Still doesn't work :(

killrwhale
05-12-2009, 11:58 PM
These are of concern, but I dont think they should prevent the file from including:



Basically you have array elemnts that are expected to be defined, but are not. The script is not checking to ensure they are defined before calling them.

what does those lines call, and whats before and after the lines? Usually a internal server error is a permission problem I think.

Yea, but the script works perfectly fine when I do not have

<?
include "../login/login.php";
?>

in it. So I am thinking it has to be something with my login script.

Jaseeey
05-13-2009, 02:27 AM
killrwhale,

Please check your cookies and ensure a cookie called PHPSESSID hasn't been set by your script. I've had this issue before, and it seems to throw a mod_security error which can only be seen in the error logs. Never exactly figured out why, unfortunately.

Take care,

tim2718281
05-13-2009, 06:15 AM
My question is, what could cause this to suddenly happen?

For example, maybe the login.php code has hit some limit - maybe it keeps log or tracking data somewhere which is now full.

Without seeing the login.php code, it's hard to guess what's wrong with it.

killrwhale
05-13-2009, 01:08 PM
For example, maybe the login.php code has hit some limit - maybe it keeps log or tracking data somewhere which is now full.

Without seeing the login.php code, it's hard to guess what's wrong with it.

Hmm, I will maybe try re-installing it. Here is the login.php code:


<?
include "include.php";

$valid = false;
$failed = false;
$posted = false;

if(isset($_POST['username'])) {
$_SESSION['username'] = $_POST['username'];
$posted = true;
}

if(isset($_POST['password']))
$_SESSION['password'] = md5($_POST['password']);

if(isset($_GET['logout']))
unset($_SESSION['username']);

if(isset($_SESSION['username']) && isset($_SESSION['password'])) {

$username = mysql_escape_string($_SESSION['username']);
$password = mysql_escape_string($_SESSION['password']);

$result = mysql_query("SELECT * FROM `users` WHERE `username` = '$username' AND `password` = '$password'");

if(mysql_num_rows($result) > 0) {
$valid = true;
if($posted) {
$user = mysql_fetch_assoc($result);
$when = time();
$ip = $_SERVER['REMOTE_ADDR'];
mysql_query("INSERT INTO `log` VALUES ('', '$user[id]', '$when', '$ip')");

$result = mysql_query("SELECT * FROM `log` WHERE `user_id` = '$user[id]'");
$ip_array = array();

while($row = mysql_fetch_assoc($result))
if(!in_array($row['ip'], $ip_array))
array_push($ip_array, $row['ip']);

if(count($ip_array) % 5 == 0) { // 5, 10, 15, 20, 25 etc
$body = "There has been ".count($ip_array)." IP's logged in as '$user[username]'\n\n";
for($i = 0; $i < count($ip_array); $i++)
$body .= "$ip_array[$i]\n";
mail(NOTIFY_EMAIL, "Login IP Overuse", $body);
}
}
} else {
$failed = true;
}
}

if(!$valid) {
include "login_page.php";
die();
}
?>

tim2718281
05-13-2009, 01:37 PM
Hmm, I will maybe try re-installing it. Here is the login.php code:


So where is it storing the session data, and what happens to the data for old sessions?

Maybe the session data is in files called /tmp/sess*

Gawlik
05-13-2009, 01:42 PM
First of all, you should check /home/public_html/error_log so show us results. Do you use suexec/suphp or any accelerator? What about php error log?

killrwhale
05-13-2009, 01:47 PM
Hey,

The only errors I get are in my original post ^^^, not related to the login script.

Gawlik
05-13-2009, 01:48 PM
It doesn`t matter, it could be related anyway. Show me http/php errors.

killrwhale
05-13-2009, 06:07 PM
These were the only errors in the log


[Mon May 11 14:53:55 2009] [error] [client 121.247.154.49] Premature end of script headers: index.php
The following errors where obtained from the custom log /home/public_html/error_log.
[11-May-2009 14:44:32] PHP Notice: Undefined offset: 3 in /home/public_html/script.php on line 91
[11-May-2009 14:44:32] PHP Notice: Undefined offset: 1 in /home/public_html/script.php on line 92
[11-May-2009 14:44:32] PHP Notice: Undefined offset: 2 in /home/public_html/script.php on line 93