Jump to content

I need some help


nepzap2

Recommended Posts

Does anyone know what where I can find information on the following.

 

I have seen several website that use a single page that then has extensions that follow the actual page. Like "page.php?id=2" or "page.php?page=home" almost like information gets re-routed through a control page that then takes care of the look of that page depending on the page itself.

 

Where can I learn more about this or is there a tutorial here that I can explore?

 

Many Thanks.

Link to comment
https://forums.phpfreaks.com/topic/179226-i-need-some-help/
Share on other sites

^beat me to it .. i'm so slow;

 

trying to keep it simple, this is a combination of a template-driven website using the $_GET superglobal for page referencing.

 

you access the variable (string) from the URL via $_GET:

 

<?php
$page = $_GET['page']; //would make $page = 'home' as per your post ("page.php?page=home");
?>

 

you could then use a switch() statement to determine which page to display:

 

<?php
$safe_urls = array ('home', 'contact', 'blog'); //add more as needed / for security;

if (in_array ($_GET['page'], $safe_urls))
{ $page = htmlentities ($_GET['page']); }

switch ($page)
{
case home: include 'homepage.php'; break;
case contact: include 'contact.php'; break;
case blog: include 'blog.php'; break;
default: include 'homepage.php'; break;
}
?>

Link to comment
https://forums.phpfreaks.com/topic/179226-i-need-some-help/#findComment-945591
Share on other sites

As mrMarcus pointed out you can add security,

but this is only needed if you use the value directly,

ie

include $_GET['page'].'.php';

which is insecure, a secure use would be

<?php
$safe_urls = array ('home', 'contact', 'blog'); //add more as needed / for security;

if (in_array ($_GET['page'], $safe_urls)){
   include $_GET['page'].'.php';
}else{
   include 'index.php'; //default page
}
?>

Link to comment
https://forums.phpfreaks.com/topic/179226-i-need-some-help/#findComment-945609
Share on other sites

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.