• Howdy! Welcome to our community of more than 130.000 members devoted to web hosting. This is a great place to get special offers from web hosts and post your own requests or ads. To start posting sign up here. Cheers! /Peo, FreeWebSpace.net
managed wordpress hosting

help with PHP on website

Silent

New Member
Not sure if this is the right place to put it but anyways. Alright so I want to do a website with PHP includes doing my content, so my page addresses will basicly be realh2o.com/index.php?id=whater Well say I want my whatever content to show up when someone goes to index.php... How would I go about doing that, I know theres a script im supposed to put in my header, I just forgot...
 
PHP:
if (!$_GET['id'] || !$_GET['id'] == '') 
    include('index.php');
else 
    include($_GET['id']);
 
kabatak said:
PHP:
if (!$_GET['id'] || !$_GET['id'] == '') 
    include('index.php');
else 
    include($_GET['id']);

That's a VERY insecure way of doing this. By not restricting "id" to a certain directory you are letting a user include any file that the server has access to.

This is a better way of doing it:

PHP:
<?php
if (empty($_GET['id']))
{
	require 'index.php';
	exit;
}

$path = baseName($_GET['id']);

if (!file_exists($path))
{
	require 'index.php'; // or make a 404.php for file not found.
	exit;
}

require $path;
?>
 
Last edited:
probably something like this:

PHP:
<?php
	include_once("include/include_header.html");

	$page=$_GET['page'];
	switch($page) {
		case about:
		include_once("html/html_about.html");
		case home:
		include_once("html/html_home.html");
		case contact:
		include_once("html/html_contact.html");
		case forum:
		include_once("html/html_forum.html");
		case other:
		include_once("html/html_other.html");
		default:
		include_once("html/html_index.html");
	}

	include_once("include/include_footer.html");
?>
 
Back
Top