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: Dynamic Pages

  1. #1
    New to the CF scene
    Join Date
    Dec 2005
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Dynamic Pages

    Hello

    Can somebody point me in the direction of a good/simple Dynamic Page tutorial? I'm fed-up of having to edit each page individually every time I edit the index page design.

    PS. I have tried Google "going on 3 hours now, but to no avail"

    Thanks very much.

  • #2
    Regular Coder Element's Avatar
    Join Date
    Jul 2004
    Location
    Lynnwood, Washington, US
    Posts
    855
    Thanks
    2
    Thanked 2 Times in 2 Posts
    A good way to do it is put your content into individual php pages, and then dynamically include them. And also its good to add mod_rewrite but I don't have time for that, gotta get some foot.

    PHP Code:
    <?php

    // PHP Include
    $page $_GET['p'];
    $i404 "home/user/public_html/404.shtml";
    $home "home/user/public_html/index_content.php"// File to your main page, like the news script or something.
    if(file_exists($page.".php")) {
      include 
    $page.".php";
    } elseif (empty(
    $page)) {
      include 
    $home;
    } else {
      include 
    $i404;
    }

    ?>
    And then you would go to lets say index.php?p=media to go to the multimedia section while still being in the same template, index.php.

    Or use mod_rewrite to turn index.php?p=media into something like /site/media.php if you don't want people seeing the real URL.

    Also I usually make an array of files I don't want people to go to, just encase.

    PHP Code:
    // PHP Include
    $page $_GET['p'];
    $i404 "home/user/public_html/404.shtml";
    $home "home/user/public_html/index_content.php"// File to your main page, like the news script or something.
    $bad_files = array ('temp/private.db''Thumbs.db''functions.php'); // Etc.
    if(file_exists($page.".php") && !(in_array($page$bad_files))) { 
    EDIT: Thanks Marek_mar, assuming thats for me. Havn't had coffee, well actually I don't have any coffee.
    Last edited by Element; 12-11-2005 at 07:52 PM.

  • #3
    Senior Coder
    Join Date
    Aug 2003
    Location
    One step ahead of you.
    Posts
    2,815
    Thanks
    0
    Thanked 3 Times in 3 Posts
    http://www.php.net/variables. The "basics" part.
    I'm not sure if this was any help, but I hope it didn't make you stupider.

    Experience is something you get just after you really need it.
    PHP Installation Guide Feedback welcome.

  • #4
    Regular Coder Element's Avatar
    Join Date
    Jul 2004
    Location
    Lynnwood, Washington, US
    Posts
    855
    Thanks
    2
    Thanked 2 Times in 2 Posts
    Also, I forgot, because these are dynamic pages, you might also want to pass the page title, to have a dynamic page title. There are a few ways to do this, I would say.

    First, if you filenames only are one word, you can echo the filename and capitalize it with ucwords(), or use a $t query for the title. Example

    PHP Code:

    <title>Example.com <?php $t=$_GET['t']; $t==""?$t="- Home":$t="- ".ucwords($t); echo $t?></title>
    Example URL example.com/index.php?p=media&t=multimedia+section

    So because $t isn't empty it will echo "Example.com - Multimedia Section" in the <title></title> tag. If its empty it would assume your on http://example.com/index.php and output "Exampe.com - Home"

  • #5
    Senior Coder
    Join Date
    Apr 2005
    Location
    Colorado, United States
    Posts
    1,208
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Also, run str_replace on the value to ensure it isn't exploited to view other files.

    PHP Code:
    <?php 

    // PHP Include 
    $page $_GET['p']; 
    $page str_replace(array('..','/','\\','.'), ''$page); // Replace any operators that would allow other-directory transversal.
    $i404 "home/user/public_html/404.shtml"
    $home "home/user/public_html/index_content.php"// File to your main page, like the news script or something. 
    if(file_exists($page.".php")) { 
      include 
    $page.".php"
    } elseif (empty(
    $page)) { 
      include 
    $home
    } else { 
      include 
    $i404


    ?>
    "$question = ( to() ) ? be() : ~be();"

  • #6
    Regular Coder Element's Avatar
    Join Date
    Jul 2004
    Location
    Lynnwood, Washington, US
    Posts
    855
    Thanks
    2
    Thanked 2 Times in 2 Posts
    Quote Originally Posted by Velox Letum
    Also, run str_replace on the value to ensure it isn't exploited to view other files.

    PHP Code:
    <?php 

    // PHP Include 
    $page $_GET['p']; 
    $page str_replace(array('..','/','\\','.'), ''$page); // Replace any operators that would allow other-directory transversal.
    $i404 "home/user/public_html/404.shtml"
    $home "home/user/public_html/index_content.php"// File to your main page, like the news script or something. 
    if(file_exists($page.".php")) { 
      include 
    $page.".php"
    } elseif (empty(
    $page)) { 
      include 
    $home
    } else { 
      include 
    $i404


    ?>
    Good thinking. I'm still trying to find my include script. It has all that and more, about 46 lines. It was on my old site but I can't find its back up unfortunately. Still looking though, thats why I'm mainly silent.

    Well since I can't find the file I'll show you the mod_rewrite rule to hite the ugly php queries.

    Code:
    RewriteEngine On
    
    # Lets start with root files #
    RewriteRule ^index.php?p=(.*)&t=(.*) /site/$2/$1.php
    # Lets start with 1 sub dir #
    RewriteRule ^index.php?p=(.*)/(.*)&t=(.*) /site/$1/$3/$2.php
    # Continue if need be with mod_rewrite #
    So th first rule changes something like:

    example.com/index.php?p=media&t=multimedia+section
    To:
    example.com/site/multimedia+section/media.php (Url you would link to)

    And for the second one it would change something like:

    example.com/index.php?p=reviews/coding&t=reviews+section:+coding
    To:
    exampe.com/site/reviews/reviews+section:+coding/coding.php

    But that will only work if you allow sub directories in the code Velox added
    Last edited by Element; 12-11-2005 at 08:47 PM.

  • #7
    Senior Coder
    Join Date
    Aug 2003
    Location
    One step ahead of you.
    Posts
    2,815
    Thanks
    0
    Thanked 3 Times in 3 Posts
    Yes Elemnt, it was for you . BTW there are ways of having variables with a number at the beginning (useless but possible). You just can't call them directly.
    I'm not sure if this was any help, but I hope it didn't make you stupider.

    Experience is something you get just after you really need it.
    PHP Installation Guide Feedback welcome.

  • #8
    Regular Coder Element's Avatar
    Join Date
    Jul 2004
    Location
    Lynnwood, Washington, US
    Posts
    855
    Thanks
    2
    Thanked 2 Times in 2 Posts
    Quote Originally Posted by marek_mar
    Yes Elemnt, it was for you . BTW there are ways of having variables with a number at the beginning (useless but possible). You just can't call them directly.
    Interesting. Using eval() or something? Hum. PM me a example.

    Also that mod_rewrite code should be placed in the .htaccess file of your root where index.php is.


  •  

    Posting Permissions

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