Jump to content

PHP help. Moderate Noob here!


Ascendant

Recommended Posts

<?php
$config["path"] = "";
$config["ext"] = ".php";

if (!isset($_REQUEST["page"])){
    $page = "main";
} else {
    $page = $_REQUEST["page"];
    $page = urldecode($page);
    $page = trim($page);
    $page = strip_tags($page);
    if (substr_count($page,"..") > 0 || substr_count($page,"~") > 0){
        $page = "main";
    }
}
$full = $config["path"] . $page . $config["ext"];
if (!is_file($full) || is_dir($full) || !file_exists($full)){
    die ("Unfortuantly the page you have requested can either not be found, or has timed out. Please contact oliver@iacademia if the problem persists.");
} else {
    require_once($full);
}
?>

 

This is the current bit of request code im using on my site currently. Yet its not flexible enough, for example, if I load up index?page=about then have a hyperlink inside about.php to another page, say, login.php, it wont work.

 

I need more flexibility, and I have noticed that sites are using hyperlinks that not only have the index?page=about, but also a wierd chunk of code that includes &:

index.php?page=main&file=article&sid=77

 

Can anybody help me edit my code to incorporate is file and sid variable?

Link to comment
https://forums.phpfreaks.com/topic/88149-php-help-moderate-noob-here/
Share on other sites

If you're intending to have the same "layout" for your pages, you can always load each new page 'inside' of the index page...kind of like:

 

<?php
require_once('header.php');
if(!isset($_REQUEST['page'])) $page = 'main';
else $page = $_REQUEST['page'];

require_once($page.'.php');

require_once('footer.php');

 

In that fashion, you can reference every page on the site through index.php?page=x

 

As far as including file and sid...

 

You'd just be adding another layer of $_GET variables that would either trigger (or not trigger) additional file-loads...

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.