Jump to content

Include Function?


attila2452

Recommended Posts

So this is my website, and I am having a few problems not visually, but technically.It has some PHP but most HTML and CSS. I am needing help to view the pages. Right now I'm using the Include Function This how it is written:

<?php 	if(file_exists("".$_GET["page"].".html")){		include("".$_GET["page"].".html");	}elseif($_GET["page"] == "view"){		include("view.php");	}elseif($_GET["page"] == ""){		include("welcome.html");	}elseif(!file_exists("".$_GET["page"].".html")){		include("badpage.html");		include("welcome.html");	}?>

Is this what I should really be using? Is there any other way to view pages? Because it seems that I can't change the title. The Include code is on the index.php page and it just uses that title for every page. Unless.. if there is another way that I could display the title of different pages using PHP and still have my include file? please let me know..any suggestions?

Link to comment
Share on other sites

use a switch

// Validate what page to show:if (isset($_GET['p'])) {	$p = $_GET['p'];} elseif (isset($_POST['p'])) { // Forms	$p = $_POST['p'];} else {	$p = NULL;}// Determine what page to display:switch ($p) {	case 'about':		$page = 'about.inc.php';		$page_title = 'jlh Designs ~ About';		break;	case 'snews':		$page = 'snews.inc.php';		$page_title = 'jlh Designs ~ sNews';		break;		case 'aef':		$page = 'aef.inc.php';		$page_title = 'jlh Designs ~ AEF';		break;	case 'gmha':		$page = 'gmha.inc.php';		$page_title = 'jlh Designs ~ GMHA';		break;			case 'contact':		$page = 'contact.inc.php';		$page_title = 'jlh Designs ~ Contact';		break;		case 'search':		$page = 'search.inc.php';		$page_title = 'jlh Designs ~ Search Results';		break;		case 'upload':		$page = 'upload.inc.php';		$page_title = 'jlh Designs ~ Upload';		break;		// Default is to include the main page.	default:		$page = 'main.inc.php';		$page_title = 'jlh Designs _ Index';		break;		} // End of main switch.// Make sure the file exists:if (!file_exists('./modules/' . $page)) {	$page = 'main.inc.php';	$page_title = 'jlh Designs ~ Main';}// Include the header file:include_once ('./includes/header.html');// Include the content-specific module:// $page is determined from the above switch.include ('./modules/' . $page);// Include the footer file to complete the template:include_once ('./includes/footer.html');?>

Link to comment
Share on other sites

use a switch
// Validate what page to show:if (isset($_GET['p'])) {	$p = $_GET['p'];} elseif (isset($_POST['p'])) { // Forms	$p = $_POST['p'];} else {	$p = NULL;}// Determine what page to display:switch ($p) {	case 'about':		$page = 'about.inc.php';		$page_title = 'jlh Designs ~ About';		break;	case 'snews':		$page = 'snews.inc.php';		$page_title = 'jlh Designs ~ sNews';		break;		case 'aef':		$page = 'aef.inc.php';		$page_title = 'jlh Designs ~ AEF';		break;	case 'gmha':		$page = 'gmha.inc.php';		$page_title = 'jlh Designs ~ GMHA';		break;			case 'contact':		$page = 'contact.inc.php';		$page_title = 'jlh Designs ~ Contact';		break;		case 'search':		$page = 'search.inc.php';		$page_title = 'jlh Designs ~ Search Results';		break;		case 'upload':		$page = 'upload.inc.php';		$page_title = 'jlh Designs ~ Upload';		break;		// Default is to include the main page.	default:		$page = 'main.inc.php';		$page_title = 'jlh Designs _ Index';		break;		} // End of main switch.// Make sure the file exists:if (!file_exists('./modules/' . $page)) {	$page = 'main.inc.php';	$page_title = 'jlh Designs ~ Main';}// Include the header file:include_once ('./includes/header.html');// Include the content-specific module:// $page is determined from the above switch.include ('./modules/' . $page);// Include the footer file to complete the template:include_once ('./includes/footer.html');?>

it doesn't work. error on line 155line 55:include ('./modules/' . $page);what is ./modules/?and also what is .inc?
Link to comment
Share on other sites

I keep all the includes in a "modules' folder. Either create that folder or remove the '/modules' from the include statement.".inc" reminds me that the file is an included file.

Link to comment
Share on other sites

I keep all the includes in a "modules' folder. Either create that folder or remove the '/modules' from the include statement.".inc" reminds me that the file is an included file.
lol would you mind adding me on MSN?attilathe.hun@hotmail.com
Link to comment
Share on other sites

Archived

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

×
×
  • Create New...