View Full Version : PHP Includes
tekni
26-11-2006, 03:57 PM
This is the right section.
Has anyone got a tutorial or some information on PHP Includes.
Thanks,
Adam Rose
Luckyrare
26-11-2006, 03:58 PM
www.php.net/include
include("file.ext");
tekni
26-11-2006, 04:02 PM
Thanks,
I need a little more than that though :P
Florx
26-11-2006, 04:33 PM
This is a bit of code i made: Hope thats what u want!
<?php
// Assign the requested page to a shorter variable for simplicity.
// The value of $_GET["page"] will be obtained from index.php?page=RIGHT_HERE
$p = $_GET["page"];
// Check for bad requests. This is necessary to prevent the wrong files
// from being included. This is a security measure.
if (strpos($p,"..")) {
// A bad request has been made, exit immediately. Do not proceed
// with the inclusion.
// strpos($p,"..") checks for presence of ".." in the page request.
// ".." can be used to access files in parent directories
die("Bad page request");
}
// File to include.
// this will be something like '/www/page.php'. If $p is empty, fall back
// main.php. THIS FILE MUST EXIST, otherwise bad things will happen.
if (!$p) $p = "main";
$content_file=$_SERVER["DOCUMENT_ROOT"]."/".$p.".php";
// See if $content_file exists. If it does not, redirect to the homepage.
if (!file_exists($content_file)) {
header("Location: {$_SERVER["PHP_SELF"]}");
exit();
}
// At this point everything is fine. Set the appropriate title and then
// include the files.
// Syntax: $variable = (condition) ? value_if_true : value_if_false;
$title = ($p) ? "$p - My Site!" : "Main page - My Site!";
include("header.php");
include($content_file);
include("footer.php");
?>
Josh-H
26-11-2006, 04:34 PM
http://us2.php.net/include/
Everything you'll ever need to know :D
tekni
26-11-2006, 04:36 PM
-cries-
I cba to learn php - I never want to.
I just need a code or whatever :P.
+Rep anywho.
Want to hide these adverts? Register an account for free!
Powered by vBulletin® Version 4.2.5 Copyright © 2026 vBulletin Solutions Inc. All rights reserved.