SitePoint Sponsor

User Tag List

Results 1 to 12 of 12

Thread: ¿php question?

  1. #1
    SitePoint Enthusiast
    Join Date
    Jul 2001
    Location
    Tucson, AZ
    Posts
    80
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    ¿php question?

    Is it possible to have a website made in php that loads each page from a txt file?
    What i mean is:
    the main page loads (index.php)
    then the user clicks a link... index.php gets reloaded with the content from a txt file.

    Pretty much each link is tied to an include or require function.

    when someone clicks on a link labeled "files" index.php gets reloaded with files.txt instead of the default index.txt

    i think this idea will allow people to have one main page for their site... It could be effecient.

    I believe it can be done...
    I dont know how...
    I have basic understanding of php...
    the majority of my knowledge is include and require functions...
    if my idea is possible... can someone help me make it reality?



  2. #2
    Node mutilating coot timnz's Avatar
    Join Date
    Feb 2001
    Location
    New Zealand
    Posts
    516
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sure you can do this, but wouldn't it be easier to pull stuff out of a database for each page and more functional.

    If you want the flat file way, you could do something like this:

    LINK: index.php?page=stuff

    then the code:

    include ($page.php)

    Or else you can do some manipulation of that by using the file functions, see php.net for more details.

    http://www.php.net/manual/en/ref.filesystem.php

  3. #3
    Grumpy Mole Man Skunk's Avatar
    Join Date
    Jan 2001
    Location
    Lawrence, Kansas
    Posts
    2,066
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you do include files based on what the user provided in the query string you need to stick in some security measures, or malicious users will be able to load up anny file on your site (even files in password protected directories). I'd suggest using the basename function to prevent people from providing a directory path:

    $page = basename($page);

  4. #4
    SitePoint Enthusiast
    Join Date
    Jul 2001
    Location
    Tucson, AZ
    Posts
    80
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm confuzed

  5. #5
    SitePoint Enthusiast
    Join Date
    Jul 2001
    Location
    Tucson, AZ
    Posts
    80
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I looked at php.net and I am still confuzed.
    Maybe its because i havent slept yet and its 6:20am.
    I think timnz has hit on what I want.
    How could I do that securely? Got a script sample I can look at? Something more than just 1 line of code?
    Sorry Like I said, I pretty much know include and require.
    I cant program php yet, but i can hack, change and modify it.
    Thats how I learned HTML.

  6. #6
    SitePoint Wizard creole's Avatar
    Join Date
    Oct 2000
    Location
    Nashvegas Baby!
    Posts
    7,845
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What Skunk is saying is that if you do it the firtst way, a user could simply type in a path to any file on your server and have it served up in your index.php page. For example, a password file, a bank statement, a JPG of Madonna, if they can find it on your file, then they can use that script to pull it into the page.

    Your code could look like this:

    PHP Code:
    <?php

    if ($page=='') {
    include (
    "index.txt")
    } else {
    include (
    $page)
    }

    ?>
    Then, for each link the user can click on you simply specify the name of the text file like so:

    <a href="index.php?page=portfolio.txt">Portfolio</a>

    Could someone tell me if the code is wrong? It was my first try.
    Adobe Certified Coldfusion MX 7 Developer
    Adobe Certified Advanced Coldfusion MX Developer
    My Blog (new) | My Family | My Freelance | My Recipes

  7. #7
    SitePoint Enthusiast
    Join Date
    Jun 2001
    Location
    Malaysia
    Posts
    60
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    if you know how to include it's enough for me ..

    it's like this (the way i make it!)

    make one directory called 'inc' or anything you want.

    and this is the index.php code:

    <html>
    <body text="#000000" bgcolor="#ffffff">
    <font face="verdana" size="2">
    <?
    if ($page == internet) {
    include ("inc/internet.inc");
    }
    elseif ($page == window98) {
    include ("inc/window98.inc");
    }
    else {
    include ("inc/index.inc");
    }
    ?>
    </font>
    </body>
    </html>

    there you're .. in internet.inc type anything about internet .. you can even put image there .. and no need to specify the font type.

    same also with window98.inc and index.inc ...

    and the url to load internet.inc file is .. index.php?page=internet
    to load window98 file ... index.php?page=window98
    and index.php would load up the index.inc

    there is a lot better site navigation system than this ..

  8. #8
    SitePoint Enthusiast
    Join Date
    Jul 2001
    Location
    Tucson, AZ
    Posts
    80
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    maelzx, I think thats it... lemme see if it works and I'll get back to you.
    Thanks guys.

  9. #9
    SitePoint Enthusiast
    Join Date
    Jul 2001
    Location
    Tucson, AZ
    Posts
    80
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    How can I use that to have unlimited amounts of includes?
    I tweaked it and I only got 3 total from it... the fourth link loaded index.inc

  10. #10
    SitePoint Enthusiast
    Join Date
    Jul 2001
    Location
    Tucson, AZ
    Posts
    80
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    is there a way I can add the page's name as part of the title?

  11. #11
    SitePoint Enthusiast
    Join Date
    Jun 2001
    Location
    Malaysia
    Posts
    60
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i've just reply to your message in my inbox ...

    i just use like this
    PHP Code:
    <?
    if ($page) {
    include (
    "inc/$page");
    }
    else {
    include (
    "inc/index.inc");
    }
    ?>
    i'm sorry in my reply message to you i didn't put the code to call index.inc. there it's.

    to call internet.inc the url is
    http://urname.com/index.php?page=internet.inc

    i still don't know if this code work. correct me if i'm wrong.

    PHP Code:
    <?
    if ($page) {
    include (
    "inc/$page.inc");
    }
    else {
    include (
    "inc/index.inc");
    }
    ?>
    because of the code $page.inc .. will return the $page value or not .. i don't know.

  12. #12
    SitePoint Enthusiast
    Join Date
    Jul 2001
    Location
    Tucson, AZ
    Posts
    80
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Okay... How could I have a different title for each inc file If I use this code?

    PHP Code:
    <? 
    if ($page == 2) { 
    include (
    "inc/2.inc"); 

    elseif (
    $page == 3) { 
    include (
    "inc/3.inc"); 

    elseif (
    $page == 4) { 
    include (
    "inc/4.inc"); 

    elseif (
    $page == 5) { 
    include (
    "inc/5.inc"); 

    elseif (
    $page == 6) { 
    include (
    "inc/6.inc"); 

    else { 
    include (
    "inc/index.inc"); 

    ?>


Bookmarks

Posting Permissions

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