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.
Page 1 of 3 123 LastLast
Results 1 to 15 of 31
  1. #1
    Regular Coder
    Join Date
    Nov 2006
    Posts
    601
    Thanks
    1
    Thanked 2 Times in 2 Posts

    chnaging content area

    hey guys... i wanna keep my main page the same but in the text area change the text depedning on the page

    i thought about using something like
    Code:
    <?
    		if (file_exists($content)) {
    		include($content);
    		} else {?>
    on index.php

    then on the pages where the content is add $content="name.php";

    i did this to show what i mean... i just wanna chnage data in contant chnage here area

    Code:
    -----------------------
    |        header             |
    |                              |
    -----------------------
    |         |                    |
    |         |                    |
    |         |    content     |
    | menu |     change     |
    |         |         here     |
    |         |                    |
    ------------------------
    Last edited by runnerjp; 02-14-2008 at 12:22 PM.

  • #2
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,525
    Thanks
    8
    Thanked 1,091 Times in 1,082 Posts
    What you're doing is fine ...

    Define $content yourself ...

    DO NOT DO ANYTHING LIKE THIS:

    <?
    $content=$_GET['content'];
    if (file_exists($content)) {
    include($content);
    } else {?>

    That opens it up for any spammer or hacker to
    put in their own URLs.


    DO SOMETHING LIKE THIS INSTEAD ...
    Your content is text files, or files stored in MySQL.

    Here's what the URL looks like.
    mywebsite.com/page.php?p=2

    <?
    $page=$_GET['p'];
    $content = "page".$page.".txt";
    if (file_exists($content)) {
    include($content);
    } else {?>

    That way, you are controlling the content file, not the user.

    Your file (such as "page12.txt") can also have PHP scripting in it.

  • #3
    Senior Coder rafiki's Avatar
    Join Date
    Aug 2006
    Location
    Floating around somewhere...
    Posts
    2,046
    Thanks
    19
    Thanked 42 Times in 42 Posts
    iframe?

  • #4
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,525
    Thanks
    8
    Thanked 1,091 Times in 1,082 Posts
    He didn't mention if a refresh is OK or not.
    <iframe> would be best if no refresh is wanted.
    (better than Javascripting).

  • #5
    Senior Coder
    Join Date
    Jan 2007
    Posts
    1,648
    Thanks
    1
    Thanked 58 Times in 54 Posts
    No, an IFrame would not be helpful here.

    This is just a basic template with a changing content area (as the subject mentions).

  • #6
    Banned
    Join Date
    Feb 2008
    Location
    Winnipeg, Canada
    Posts
    396
    Thanks
    0
    Thanked 29 Times in 29 Posts
    Ew, Iframes are never the way to go.

    Why not just define which pages you want to use? EG:

    PHP Code:
    <?php

    if ($_GET["page"] == "about")
       include(
    "about.php");
    elseif (
    $_GET["page"] == "contact")
       include(
    "contact.php");
    elseif (
    $_GET["page"] == "services")
       include(
    "services.php");
    else
       include(
    "home.php");

    ?>
    What I like about this is that since it's on a template you only have to change it in one place, also take note of the else include("home.php"); because that means if the user goes to either page.php or page.php?page=anything-not-defined then they get the home page.

  • #7
    Senior Coder
    Join Date
    Jan 2007
    Posts
    1,648
    Thanks
    1
    Thanked 58 Times in 54 Posts
    PHP Code:
    if ($_GET["page"] == "about")
       include(
    "about.php");
    elseif (
    $_GET["page"] == "contact")
       include(
    "contact.php"); 
    Do realize that this is an inefficient setup. And the whole point of a programming language is to make it easier for you to make. Otherwise we might as well just stick with HTML.

    Check my suggestion on this thread: http://www.codingforums.com/showthread.php?t=133261

  • #8
    Banned
    Join Date
    Feb 2008
    Location
    Winnipeg, Canada
    Posts
    396
    Thanks
    0
    Thanked 29 Times in 29 Posts
    So you're saying what? Put them into an array instead of listing them? Your linked code doesn't have all the same functionality either.

    *This text removed by moderator*
    Last edited by JohnDubya; 02-14-2008 at 05:00 PM. Reason: removed personal attack

  • #9
    Senior Coder
    Join Date
    Jan 2007
    Posts
    1,648
    Thanks
    1
    Thanked 58 Times in 54 Posts
    Ignore the hidden nav section code.

    PHP Code:
    $section $_GET['section'];
    $file 'includes/'.$section.'.php';
    if (
    file_exists($file)) {
        include 
    $file;

    This doesn't require updating every time you add a page while still being secure enough (although you should probably filter $section so that it only has numbers and letters).

  • #10
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,525
    Thanks
    8
    Thanked 1,091 Times in 1,082 Posts
    <iframes> have nothing to do with what content to appear ...
    the iframe would be for changing the content in one section
    without refreshing the whole page. He didn't specify if the
    page can or cannot be refreshed.

    The "include" issue can be anything really ... just so it's
    protected from injection.

  • #11
    Senior Coder
    Join Date
    Jan 2007
    Posts
    1,648
    Thanks
    1
    Thanked 58 Times in 54 Posts
    Correct, refreshing or not was not mentioned. Though it's simpler to use the include construct.

  • #12
    Regular Coder
    Join Date
    Nov 2006
    Posts
    601
    Thanks
    1
    Thanked 2 Times in 2 Posts
    wow ok im a little confused at the moment with all the replys lol

    i want it so if a go to www.mypage.com/profile.php then tho profile will be shown on the content area

    or www.mypage.com/about.php then about would be shown in content area
    PHP Code:
    -----------------------
    |        
    header             |
    |                              |
    -----------------------
    |         |                    |
    |         |                    |
    |         |    
    content     |
    menu |     change     |
    |         |         
    here     |
    |         |                    |
    ------------------------ 

  • #13
    Senior Coder
    Join Date
    Jan 2007
    Posts
    1,648
    Thanks
    1
    Thanked 58 Times in 54 Posts
    Read my code suggestion.

  • #14
    Regular Coder
    Join Date
    Nov 2006
    Posts
    601
    Thanks
    1
    Thanked 2 Times in 2 Posts
    humm ok could you explain a little more hwo it works if that ok im alittle confused by it

  • #15
    Senior Coder
    Join Date
    Jan 2007
    Posts
    1,648
    Thanks
    1
    Thanked 58 Times in 54 Posts
    index.php
    PHP Code:
    include 'header.php';

    if (isset(
    $_GET['section'])) {
        
    $section $_GET['section'];
    } else 
    $section 'home';

    $file 'includes/'.$section.'.php';
    if (
    file_exists($file)) {
        include 
    $file;
    }  

    include 
    'footer.php'
    You'd call each page like this:

    index.php?section=home
    index.php?section=about

    Etc.

    So in the end you'd need to have index.php, header.php, footer.php, a folder called 'includes' and in there you'd place all the different pages such as about.php, home.php, etc.


  •  
    Page 1 of 3 123 LastLast

    Posting Permissions

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