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

Link to comment
Share on other sites

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');
}
?>

Link to comment
Share on other sites

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";

    }
}
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.