php site help. 500 error.
Moderator: General Moderators
-
luke_barnes
- Forum Newbie
- Posts: 6
- Joined: Thu Apr 09, 2009 6:45 pm
php site help. 500 error.
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
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.
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
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.
Notice: Undefined index: page in C:\wamp\www\bulldogs\index.php on line 45
what is on line 45 of the index
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.
$page = $_GET['page'];
thats line 45
thats line 45
Re: php site help. 500 error.
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.
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.
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.
You could still be trying to include a file that doesn't exist. This is how I recommend you validate pages:
That way you will only include pages you have previously defined.
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';Re: php site help. 500 error.
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.
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'];
...
?>
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'];
...
?>