php site help. 500 error.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
luke_barnes
Forum Newbie
Posts: 6
Joined: Thu Apr 09, 2009 6:45 pm

php site help. 500 error.

Post by luke_barnes »

http://www.miltonsjoybulldogs.co.uk/

This is a simple php site i have made for my mother, however i am having trouble with the first page.

<?php

$page = $_GET['page'];
if ($page)
{
include("inc/".$page.".php");
}
else
{
include("inc/home.php");
}
?>

i have used this code to connect each part of the website and they all work bar the home page.

when running on a local host i get this message but the page works:

Notice: Undefined index: page in C:\wamp\www\bulldogs\index.php on line 45

however when hosted the front page does not work and i get a 500 error.

http://www.miltonsjoybulldogs.co.uk/ind ... ge=aboutus
as you can see the site works just not the front page.

i dont know what im doing wrong as this seems such a simple simple site. any help would be great

Thanks
Luke
Eric!
DevNet Resident
Posts: 1146
Joined: Sun Jun 14, 2009 3:13 pm

Re: php site help. 500 error.

Post by Eric! »

Your include path on your host site is probably different than on your local test system. If your index.php file is under the http served root directory /inc/index.php then try something like:

include("./inc/".$page.".php");

Host providers often have full paths that look like this or something similar
/username/public_html/your_root_web_files
towerspl
Forum Newbie
Posts: 20
Joined: Mon Aug 03, 2009 7:37 am

Re: php site help. 500 error.

Post by towerspl »

Notice: Undefined index: page in C:\wamp\www\bulldogs\index.php on line 45


what is on line 45 of the index
luke_barnes
Forum Newbie
Posts: 6
Joined: Thu Apr 09, 2009 6:45 pm

Re: php site help. 500 error.

Post by luke_barnes »

$page = $_GET['page'];

thats line 45
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: php site help. 500 error.

Post by jackpf »

Use isset() to check if $_GET['page'] exists before using it. If "page" is not in the query string, you will get that error, because $_GET['page'] is undefined.

Also, you may want to check that the file exists before including it. If I were to put ?page=jhadskgh in the url, obviously jhadskgh.php (probably) does not exist, so you will get an include error.

Also, you shouldn't have errors turned on on a live server anyway.
cpetercarter
Forum Contributor
Posts: 474
Joined: Sat Jul 25, 2009 2:00 am

Re: php site help. 500 error.

Post by cpetercarter »

If you call your home page "Page 1", then the following simple code will work:

Code: Select all

$page = 1;
if(isset($_GET['page'])) $page = $_GET['page'];
include 'inc/page'.$page.'.php';
 
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: php site help. 500 error.

Post by jackpf »

You could still be trying to include a file that doesn't exist. This is how I recommend you validate pages:

Code: Select all

$valid_pages = array('index', 'anotherpage', 'page');
 
$page = (isset($_GET['page']) && in_array($_GET['page'], $valid_pages)) ? $_GET['page'] : 'index';
 
include 'includes/'.$page.'.php';
That way you will only include pages you have previously defined.
towerspl
Forum Newbie
Posts: 20
Joined: Mon Aug 03, 2009 7:37 am

Re: php site help. 500 error.

Post by towerspl »

i would personally use a switch

Code: Select all

 
 
if(isset($_GET['page']) {
       $page = intval($_GET['page']);
}else{
      $page = 1;
}
 
 
switch($page) {
 
case 1:
 
 
    break;
 
 
case 2:
 
 
    break;
 
default:
 
 
    break;
}
 
rueben.w
Forum Newbie
Posts: 2
Joined: Thu Jul 23, 2009 4:44 am

Re: php site help. 500 error.

Post by rueben.w »

This is a warning,because $_GET['page'] is undefined.

Ways:
1. Modify php.ini
Found error_reporting = E_ALL;
Modify error_reporting = E_ALL & ~E_NOTICE;

2.Modify php.ini:
Found register_globals = Off;
Modify register_globals = On;

3.
<?php
$page=isset($_GET[page]) ? $_GET[page] : '';
...
?>

4.
<?php
error_reporting(E_ALL ^ E_NOTICE);
$page = $_GET['page'];
...
?>
Post Reply