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
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...

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.