views:

63

answers:

3
+1  Q: 

PHP syntax errors

My ISPs PHP server is now returning

500 - Internal server error. There is a problem with the resource you are looking for, and it cannot be displayed.

On what I thought was valid php, i.e.

if ( $_REQUEST[ 'some_data' ] == null )
{
  echo "<p>No data</p>";
}
else
{
  echo "<p>Some data</p>";
}

I have tried turning on error reporting with

error_reporting(E_ALL);
if (!ini_get('display_errors')) 
{
  ini_set('display_errors', "stderr");
}

So whilst I can make my code work by enclosing all checks of values in arrays with

if ( isset( $_REQUEST[ 'some_data' ] ) )
{
  // ... do stuff
}

I don't understand and dianognois of errors is now taking a very long time. Can anyone give me a clue what is going on?

+1  A: 

The error is not in your PHP script, but probably somewhere in the configuration of your webserver (.htaccess?) or the path or filename you are trying to access.

If you are not the administrator, check if other sites at your ISP are experiencing problems. Maybe your ISP is working on their webserver?

Wil
A: 

The problem with the code is that NULL != NULL. You're better off asking "if empty($somevar)..."

As far as your 500 error, I wouldn't expect the code you've posted to affect that.

dnagirl
A: 

I looks like your ISP has a very tight grip on PHP configuration. I would recommend that you develop all of your code on your local server, make sure it runs with E_ALL (perhaps E_STRICT if it's PHP5) and only then upload it to the server.

And not properly checking if a variable is set is plain and simply bad coding. Make sure you check that the value in the array is set by always using isset or array_key_exists.

Miha Hribar