Page 1 of 1

php site help. 500 error.

Posted: Mon Aug 03, 2009 8:02 am
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

Re: php site help. 500 error.

Posted: Mon Aug 03, 2009 8:17 am
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

Re: php site help. 500 error.

Posted: Mon Aug 03, 2009 8:19 am
by towerspl
Notice: Undefined index: page in C:\wamp\www\bulldogs\index.php on line 45


what is on line 45 of the index

Re: php site help. 500 error.

Posted: Mon Aug 03, 2009 8:23 am
by luke_barnes
$page = $_GET['page'];

thats line 45

Re: php site help. 500 error.

Posted: Mon Aug 03, 2009 8:27 am
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.

Re: php site help. 500 error.

Posted: Mon Aug 03, 2009 1:16 pm
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';
 

Re: php site help. 500 error.

Posted: Mon Aug 03, 2009 2:06 pm
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.

Re: php site help. 500 error.

Posted: Tue Aug 04, 2009 9:26 am
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;
}
 

Re: php site help. 500 error.

Posted: Tue Aug 04, 2009 3:18 pm
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'];
...
?>