Jump to content

~~~ In need of a simple php code ~~~


mxdan

Recommended Posts

Ok, so I had this code from a friend that divides the layout into top.html and bottom.html. In between is your different html pages and bringing it all together is the php code. It also makes the url look like:

http://somename.com/index.php?page=content

 

I lost one of the pages to allow me to do the php. But I have these php files:

 

phpinfo.php

pages.php

utils.php

 

The codes on the pages look like this:

 

Pages.php

<?php

if ($_GET['page']!=""){

  $load = $_GET['page'];

}

else{

  $load = "$root_path/main.html";

}

switch ($page){

 

// To add a page, copy text below. Past it right below the last entry at the bottom.

 

case "[LINK NAME!]":

    $load = "$root_path/[PAGE URL NAME]";

  break;

 

// Delete [LINK NAME!] (with the brackets) and replace it with what the link name is. IE: "index.php?page=bananas" Replace it with "bananas"

// Delete [PAGE URL NAME] and replace it with the actual page url. IE: if the actual page url is "animexe.com/bananas.html", then replace it as "bananas.html"

 

//below this is the main pages

 

utils.php

<?php

$root_url = "http://name.com";

$root_path = ".";

?>

 

phpinfo.php

<?php echo phpinfo() ?>

 

_____________________________________________

 

The last code is for the top.html and bottom.html combining.

 

Thanks in advanced =]

Link to comment
https://forums.phpfreaks.com/topic/39004-~~~-in-need-of-a-simple-php-code-~~~/
Share on other sites

I suggest looking up GET and include().

 

I would just do something like:

 

<?php
$folder = "content/"; //folder to look for the html files in
include("top.html"); //include the top
$page = $_GET['page']; // set ?page= to $page
$page = preg_replace("[^A-Za-z0-9\_\-\.]", "", $page); //replace anything thats not alphanumeric, -,_, or . with blankness
if(file_exists($folder . $page . ".html")) { //if the file exists
include($folder . $page . ".html"); //include the file
}
else {
echo "Page Not Found"; //if it doesnt exist
}
include("bottom.html"); //include the bottom
?>

Archived

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

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.