Jump to content

error 500 when if (!$_GET['page']) { at top of page


shocker-z

Recommended Posts

hi im having an issue ive never come across before..

 

OS: Windows 2003 Server

Webserver: IIS 6

PHP: 5.2.4

MySQL: 5.0

 

 

if i have this code at the top of my page then i get "HTTP 500 Internal Server Error" but remove it and it works fine cept im getting, call to undifined function mysql_connect() which ive followed about 5 guides to fix and was unable to resolve so help on that would be appreciated too.

 

<?php
if (!$_GET['page']) {
header("location: index.php?page=home");
} else {
$page=$_GET['page'].'.php';
include('connect.php');
}
?>

 

regards

Liam

Try:

<?php
if ($_GET['page'] == NULL) {
header("location: index.php?page=home");
} else {
$page=$_GET['page'].'.php';
include('connect.php');
}
?>

 

or:

<?php
if (!$_SERVER['QUERY_STRING']) {
header("location: index.php?page=home");
} else {
$page=$_GET['page'].'.php';
include('connect.php');
}
?>

Could i also advise something,

 

by simply doing this:

 

$page=$_GET['page'].'.php';

include('connect.php');

 

Your are really leavaing yourself open, I'd advise setting a file_exists() function in there..

 

<?php
if ( !isset($_GET['page']) ) {

  header("location: index.php?page=home");

} else {
  $page = $_GET['page'].'.php';

  if(file_exists($page) {

    include('connect.php');

    } else {

    echo "404";

    }
}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.