Results 1 to 9 of 9

Thread: php question

  1. #1
    Join Date
    Jun 2001
    Location
    Cheltenham
    Posts
    2,618

    php question

    ok, this will either make no sense at all, or it will be blindingly obveous!

    Ok....

    What i want to do is to have one page, say page.php which is a template. That page will remain exactly the same, except for the main content of the page.

    What i want to do is construct the one page, and be able to then 'call' the content via a url variable.

    ie.

    if i was to call page.php?content=plans it would display the main template with the plans content inserted, perhaps from a text file or something.

    and if possible.... (though not required!!!!)

    if i just call the page.php file, it just displays the template with a predefined default bit of contect, such as an index file.

    so, am i living in the clouds? can this be done? how can i do it? (idiots guide please!)

    any / all help appriciated.
    l 201TB.com • 201TB bandwidth as standard in three USA DC’s. KVMoIP, auto reboot & OS install all included - Now available in the Netherlands!
    l udedi.com • UK, USA & NL unmetered 100mb & 1GB 100TB premium bandwidth servers
    l Assiva Ltd • UK Shared & Reseller LiteSpeed • 10 years of hosting • R1Soft

  2. #2
    Join Date
    Aug 2001
    Location
    Matrix
    Posts
    2,469
    make an array for text files to be included or match the variable with switch to display particular file depending upon $contents value or when particular string matches with array string.

    for example if

    page.php?contents=plans then plans.txt should be included.

    also at top keep the code to check if varible contents is set or not. if not then fill it with index.

    if (!isset($contents)) {
    $contens="index.txt";
    }

    so if somebody calls page.php then it will show default page.

    CPHosting - Web Hosting Experts Since 1998.
    United States | Europe | Singapore | Australia
    Visit Us! www.cphosting.com

  3. #3
    thebyp2, lets look at the following :

    page.php -> this contains all your php code..
    plans.txt -> this contains all your html...

    now, in plans.txt you could have a word like this -> {replace_contents_here}

    Now, your page.php would contain this :

    PHP Code:
    <?
    /* now $html contains your entire plans.txt file */

    $file file('/paht/to/plans.txt');
    for(
    $i=0$i++; $i<count($file) {
    $html .= $file[$i];
    }

    /*we now replace {replace_contents_here} */

    $html str_replace('replace_contents_here'$contents$html);

    /* we now echo the html */

    echo $html;
    ?>
    that should do it.
    The Php Support Desk
    http://www.phpsupportdesk.com
    Custom programming - kunal @ e-phoria.com
    http://www.pingzine.com - Ping!Zine. the FREE, FRESH and EXCITING Web Hosting Magazine...

  4. #4
    Join Date
    Jan 2002
    Posts
    453

    good book on the subject..

    http://www.sitepoint.com/books/

    Kevin's written a good book on the subject..

  5. #5
    Join Date
    Jun 2001
    Location
    Cheltenham
    Posts
    2,618
    what i really want to do is not specify any variables of the txt files in the code.

    i wanted a kind of dynamic php include statement in the template

    so you kind of have include /path/to/text/file/$content.txt

    Basically so i post page.php?content=plans and it replaces the content variable in the include path to /path/to/text/file/plans.txt

    i have tried the echo statement, but that does not seem to work.
    l 201TB.com • 201TB bandwidth as standard in three USA DC’s. KVMoIP, auto reboot & OS install all included - Now available in the Netherlands!
    l udedi.com • UK, USA & NL unmetered 100mb & 1GB 100TB premium bandwidth servers
    l Assiva Ltd • UK Shared & Reseller LiteSpeed • 10 years of hosting • R1Soft

  6. #6
    Join Date
    Dec 2000
    Posts
    1,280
    In the code kunal provided, replace $file = file('/paht/to/plans.txt'); with $file = file('/paht/to/plans.txt')); and it should work.
    (SH)Saeed

  7. #7
    Originally posted by thebyp2
    so you kind of have include /path/to/text/file/$content.txt

    Basically so i post page.php?content=plans and it replaces the content variable in the include path to /path/to/text/file/plans.txt


    Doing something like this is a very bad idea.. unless you can pass only an ID in the url, and then reference that ID to a file list in your php code. This because you would be giving the user control over the file name to be attacht to this program, which is not a very clever thing to do...
    The Php Support Desk
    http://www.phpsupportdesk.com
    Custom programming - kunal @ e-phoria.com
    http://www.pingzine.com - Ping!Zine. the FREE, FRESH and EXCITING Web Hosting Magazine...

  8. #8
    Join Date
    Jun 2001
    Location
    Cheltenham
    Posts
    2,618
    but if i did want to do it???

    and logically, if it is only inlcuding files from a certain directory then they can only call what you want them to?
    l 201TB.com • 201TB bandwidth as standard in three USA DC’s. KVMoIP, auto reboot & OS install all included - Now available in the Netherlands!
    l udedi.com • UK, USA & NL unmetered 100mb & 1GB 100TB premium bandwidth servers
    l Assiva Ltd • UK Shared & Reseller LiteSpeed • 10 years of hosting • R1Soft

  9. #9
    Join Date
    Jan 2002
    Location
    Kuwait
    Posts
    679
    Originally posted by thebyp2
    but if i did want to do it???

    and logically, if it is only inlcuding files from a certain directory then they can only call what you want them to?
    Not really ..
    but if you insist, you can check the variable you are using and make sure that it doesn't include any dots or slashes in it.

    If you use the script above, someone can do something like this:

    Code:
    page.php?file=../../../../../now_i_am_out_of_the_the_directory/
    As you are inforcing the ".txt" bit, this might be limited to getting files on the server with the .txt extension. But an experienced person can do something about it and make your script omit the .txt part (maybe by putting a null character before it?), and they will be able to get the contents of any file that apache has access to (including the sources of all other files, including the files containing DB or other passwords).
    Ahmad Alhashemi
    PHP, Apache, C, Python, Perl, SQL
    18 related BrainBench certificates

Posting Permissions

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