Jump to content

Need help FAST.


Kynetek

Recommended Posts

Ok. I know what I need is something simple, but I just can't remember exactly what the code for it is.

 

Basically I have a file, my .php file. But what I want to do is make an include that allows me to click a link and it'll include it into the main content table of the page...

 

All I can really remember is that the URL I used to use looked something like this:

 

http://http://free.hostultra.com/~kynetek/index2.php?id=News/News.html

 

If someone could help me i'd be godly greatful...

Link to comment
https://forums.phpfreaks.com/topic/44607-need-help-fast/
Share on other sites

$page = $_GET['id'];
include("$page");

Ted

That is extremely insecure!

 

I would do something like this:

if(isset($_GET['id']))
{
    $page = $_SERVER['DOCUMENT_ROOT'] . '/' . $_GET['id'];

    if(file_exists($page))
    {
        include "$page";
    }
    else
    {
        die($page . ' cannot be found!');
    }
}

That is much more secure.

Link to comment
https://forums.phpfreaks.com/topic/44607-need-help-fast/#findComment-216938
Share on other sites

 

That is extremely insecure!

 

I would do something like this:

if(isset($_GET['id']))
{
    $page = $_SERVER['DOCUMENT_ROOT'] . '/' . $_GET['id'];

    if(file_exists($page))
    {
        include "$page";
    }
    else
    {
        die($page . ' cannot be found!');
    }
}

That is much more secure.

 

errr..... 

 

url.php?id=../../../somefile.php

 

You'd be far better off cleansing that variable prior to using it. eg. intval($_GET['id']) or at least stripping out any ".." from it.

 

 

Link to comment
https://forums.phpfreaks.com/topic/44607-need-help-fast/#findComment-216942
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.