Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8

Thread: name.php?id=

  1. #1
    Regular Coder GO ILLINI's Avatar
    Join Date
    Jun 2005
    Location
    USA
    Posts
    634
    Thanks
    0
    Thanked 7 Times in 7 Posts

    name.php?id=

    sorry new to php? 5 second script though it seems.
    I have a page that acts as a gateway to all other pages right now but my script is to complex.
    I want page.php?id=9th_mythic_funcube_v1
    right now its in an array and id=0 will give you first one 1 second one and so on but i changed my mind and just want id.php but include $id.php didnt work.
    ideas?

    EDIT: I would also like there to be an else map_error.php includei can use something like allowed.txt or something but i dont wanna make any long list internal.(easier to add to database if external.
    Last edited by GO ILLINI; 09-07-2005 at 03:55 AM.
    Why not thank me?

    http://adamsworld.name

  • #2
    Senior Coder missing-score's Avatar
    Join Date
    Jan 2003
    Location
    UK
    Posts
    2,194
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I think you mean you want to include the file shown in the id... this is a very bad idea, becuase somebody could start including files you dont want them to! The best bet is to have an array of keys and values to check in (like this):

    PHP Code:
    <?php
    $pages 
    = array();

    $pages['first_page.php'] = 'first_page';
    $pages['9th_mythic_funcube_v1.php'] = '9th_mythic_funcube_v1';
    $pages['second_page.php'] = 'second_page';
    ?>
    You can list as many pages as you need, using a similar format to the others... Then, when the user visits your page, use the $_GET var ($_GET is the proper way to retrieve URL variables (eg: page.php?id=123&value456)...

    PHP Code:
    <?php
    if(false !== ($pagename array_search($_GET['id'], $pages)))
    {
      require(
    $pagename);
    }
    else
    {
      require(
    'error_page.php');
    }
    ?>
    Hope that may help you out a bit.

  • #3
    Regular Coder GO ILLINI's Avatar
    Join Date
    Jun 2005
    Location
    USA
    Posts
    634
    Thanks
    0
    Thanked 7 Times in 7 Posts
    yes it does thanks. But is there a way to have the allowed pages in another file? because I plan to have alot of pages. like allowed.txt?
    Why not thank me?

    http://adamsworld.name

  • #4
    Regular Coder
    Join Date
    Feb 2005
    Location
    West Midlands, UK
    Posts
    623
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Put the pages array in your separate file called whatever you want, e.g. "allowed.php":

    PHP Code:
    <?php
    //content of allowed.php
    $pages = array();

    $pages['first_page.php'] = 'first_page';
    $pages['9th_mythic_funcube_v1.php'] = '9th_mythic_funcube_v1';
    $pages['second_page.php'] = 'second_page';
    ?>
    Then in your main script use an include() to include the contents of your separate file:

    PHP Code:
    <?php
    include_once('allowed.php');
    if(
    false !== ($pagename array_search($_GET['id'], $pages)))
    {
      require(
    $pagename);
    }
    else
    {
      require(
    'error_page.php');
    }
    ?>

  • #5
    Regular Coder GO ILLINI's Avatar
    Join Date
    Jun 2005
    Location
    USA
    Posts
    634
    Thanks
    0
    Thanked 7 Times in 7 Posts
    what woul;d the script be for a box thats kind of a search box... what i mean is that i dont want it to be a database or anything i just want it to be a box that adds "http://adamsworld.name/css/maps.php?search=yes&id="before what you enter so it will be:
    http://adamsworld.name/css/maps.php?search=yes&id=(what you enter)
    what i want search for is a different error_page_search.php if search = yes but if it = nothing or doesnt exist it will go to error_page.php(normal one). So I can keep my links without search, but the box will add it along with the rest of the link.
    -Thanks
    Why not thank me?

    http://adamsworld.name

  • #6
    Regular Coder
    Join Date
    Jan 2005
    Posts
    153
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Cant you do this:
    PHP Code:
    $id $HTTP_GET_VARS['id'];

    if(!isset(
    $id) || $id == '')
    {
    include(
    'index.php');
    }
    if(!
    file_exists('domain.com/directory/' $id '.php'))
    {
    die(
    '404 file not found!');
    }
    else
    {
    include(
    'domain.com/directory/' $id '.php');

    That's safe because users can only include files that are in that directory (or subdirectories) and have the extension .php. They can't include a bad file from their site because it's not in that directory. If it was just include($id . '.php'), then you could do this: ?id=http://domain.com/badscriptthaterasesyourdatabaseanddestroysyourfiles and it wuold work. But with it needing to be in that directory, unless someone else has access to your FTP and uploads the file, they couldn't do that.

    See what I'm saying? Am I being too... repititous? I just like this idea better because then you don't need to edit that file everytime you make a new file and want to allow it. It is always allowed. Of course, you can always make a dissallowed files file if you want...
    -Yaggles

  • #7
    Regular Coder GO ILLINI's Avatar
    Join Date
    Jun 2005
    Location
    USA
    Posts
    634
    Thanks
    0
    Thanked 7 Times in 7 Posts
    thanks ill try it out
    but any ideas with my "search" box?
    Why not thank me?

    http://adamsworld.name

  • #8
    Regular Coder
    Join Date
    Jan 2005
    Posts
    153
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I dont know... I would have to think about it it a bit. Sorry. If I figure it out, I'll post here, if no one already did!

    -Yaggles


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •