500 Internal Server Error
Discussion
Just released a PHP/HTML website onto a live environment. The code runs perfectly on my hosting company's server.
However, on the live env, most of the files work, but one doesn't.
I can see index.php and other pages, but if I try to look at contact.php I get a 500 Internal Server Error.
If it was permissions or something then surely nothing would work? Any ideas?!
However, on the live env, most of the files work, but one doesn't.
I can see index.php and other pages, but if I try to look at contact.php I get a 500 Internal Server Error.
If it was permissions or something then surely nothing would work? Any ideas?!
evenflow said:
Just released a PHP/HTML website onto a live environment. The code runs perfectly on my hosting company's server.
However, on the live env, most of the files work, but one doesn't.
I can see index.php and other pages, but if I try to look at contact.php I get a 500 Internal Server Error.
If it was permissions or something then surely nothing would work? Any ideas?!
What does the servers log file say ? If I had to guess, has someone updated the contact email address from a test to real email and mucked it up; missed a quote or something ?However, on the live env, most of the files work, but one doesn't.
I can see index.php and other pages, but if I try to look at contact.php I get a 500 Internal Server Error.
If it was permissions or something then surely nothing would work? Any ideas?!
Well, I resolved it, but I'm not sure how.
The code at the very top of the file was originally:
<?php
$urlID = "";
$urlID = $_GET['urlid'];
?>
I replaced this with:
<?php
$urlID = "";
if (!empty($_GET['urlid']))
{
$urlID = $_GET['urlid'];
}
?>
and it runs. I didn't think you had to check for empty before trying to assign a variable like this?
The code at the very top of the file was originally:
<?php
$urlID = "";
$urlID = $_GET['urlid'];
?>
I replaced this with:
<?php
$urlID = "";
if (!empty($_GET['urlid']))
{
$urlID = $_GET['urlid'];
}
?>
and it runs. I didn't think you had to check for empty before trying to assign a variable like this?
evenflow said:
Well, I resolved it, but I'm not sure how.
The code at the very top of the file was originally:
<?php
$urlID = "";
$urlID = $_GET['urlid'];
?>
I replaced this with:
<?php
$urlID = "";
if (!empty($_GET['urlid']))
{
$urlID = $_GET['urlid'];
}
?>
and it runs. I didn't think you had to check for empty before trying to assign a variable like this?
D'oh! That's a classic script error. What happens is that the $_GET['urlid'] returns an empty string so the assignment becomesThe code at the very top of the file was originally:
<?php
$urlID = "";
$urlID = $_GET['urlid'];
?>
I replaced this with:
<?php
$urlID = "";
if (!empty($_GET['urlid']))
{
$urlID = $_GET['urlid'];
}
?>
and it runs. I didn't think you had to check for empty before trying to assign a variable like this?
$urlID =
which is incomplete.
In other languages, the solution is to wrap the potentially empty result in a set of quotes which still allows it to be parsed and substituted by the interpreter - usually that means double quotes - so that if the result is an empty string, it will be a quoted empty string, which is still valid for the assignment.
So - does
$urlID="$_GET['urlid']" ;
work instead of your solution ? (according to the PHP docs it should, but I don't have time to verify it here today).
marshalla said:
evenflow said:
Well, I resolved it, but I'm not sure how.
D'oh! That's a classic script error. What happens is that the $_GET['urlid'] returns an empty stringBut now that we've found the cause of the problem, what would cause evenflow's code to work on the dev server but fail on the live one?
jamieboy said:
But now that we've found the cause of the problem, what would cause evenflow's code to work on the dev server but fail on the live one?
Yes, exactly that. That's why I thought PHP handled empty variable assignments as no error on the dev server/test environment.Maybe to do with the level of script error reporting set in the php.ini file?
marshalla said:
evenflow said:
Well, I resolved it, but I'm not sure how.
The code at the very top of the file was originally:
<?php
$urlID = "";
$urlID = $_GET['urlid'];
?>
I replaced this with:
<?php
$urlID = "";
if (!empty($_GET['urlid']))
{
$urlID = $_GET['urlid'];
}
?>
and it runs. I didn't think you had to check for empty before trying to assign a variable like this?
D'oh! That's a classic script error. What happens is that the $_GET['urlid'] returns an empty string so the assignment becomesThe code at the very top of the file was originally:
<?php
$urlID = "";
$urlID = $_GET['urlid'];
?>
I replaced this with:
<?php
$urlID = "";
if (!empty($_GET['urlid']))
{
$urlID = $_GET['urlid'];
}
?>
and it runs. I didn't think you had to check for empty before trying to assign a variable like this?
$urlID =
which is incomplete.
In other languages, the solution is to wrap the potentially empty result in a set of quotes which still allows it to be parsed and substituted by the interpreter - usually that means double quotes - so that if the result is an empty string, it will be a quoted empty string, which is still valid for the assignment.
So - does
$urlID="$_GET['urlid']" ;
work instead of your solution ? (according to the PHP docs it should, but I don't have time to verify it here today).
The issue here is that PHP is throwing an error as it can't find the key within the $_GET array. The difference between production and dev boxes is that Production servers don't allow continuation after an error has been thrown whereas the dev boxes do.
The correct way to fix it has already been done (check if the variable is set), but you could always set the php ini settings within the script. Incidently, you could always replace your fix with the shorthand:
<?php
$urlID = (isset($_GET['urlid'])) ? $_GET['urlid'] : '';
?>
This defaults the string to '' if urlid isn't present within your query string.
As an aside, if you're using the urlid within a SQL query, make sure you have escaped it first (use mysql_real_escape_string) which will help stop SQL injection attacks.
Gassing Station | Computers, Gadgets & Stuff | Top of Page | What's New | My Stuff


