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 7 of 7
  1. #1
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts

    Dynamic includes?

    How can I write a dynamic include? This is what I have , but it's just writing it onto the screen as text:

    PHP Code:
    session_start();
    if(
    session_is_registered("username")) {
        
    $nav 'include("includes/nav2.php")';
    }
    else
    {
        
    $nav 'include("includes/nav.php")';
    }

    echo 
    $nav

  • #2
    New Coder
    Join Date
    Jun 2002
    Location
    Paris, France
    Posts
    47
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Try :
    PHP Code:
    session_start();
    if(
    session_is_registered("username")) {
        
    $nav_array file("includes/nav2.php");
        
    $nav implode(" "$nav_array);
    }
    else
    {
        
    $nav_array file("includes/nav.php");
        
    $nav implode(" "$nav_array);   
    }

    echo 
    $nav
    Should work...

    EDIT :

    Also you could use a user defined function.
    PHP Code:
    session_start();

    function 
    fetch_include($url){
        
    $nav_array file($url);
        
    $nav implode(" "$nav_array);
        return 
    $nav;
    }

    if(
    session_is_registered("username")) {
        
    $nav fetch_include("includes/nav2.php");
    }
    else
    {
        
    $nav fetch_include("includes/nav.php");

    Last edited by Flamerule; 07-09-2002 at 07:55 PM.
    I don't suffer from insanity, I enjoy every single minute of it!

  • #3
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    Thanks Worked perfectly

  • #4
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,073
    Thanks
    11
    Thanked 98 Times in 96 Posts
    errr why wont this work?


    PHP Code:
    session_start();
    if(
    session_is_registered("username")) {
       include(
    "includes/nav2.php");
    }
    else
    {
       include(
    "includes/nav.php");

    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  • #5
    Regular Coder
    Join Date
    Jul 2002
    Location
    London, UK
    Posts
    126
    Thanks
    0
    Thanked 0 Times in 0 Posts
    It does work... I completely sympathise with your confusion here...

  • #6
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    It's coz I've got includes all over the place , so instead of having that code all over, I can cut it down to variables.

  • #7
    Regular Coder
    Join Date
    May 2002
    Location
    London, England
    Posts
    367
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I'm with firepages here, there's no need to define a variable with the location, and then include it.

    Jee
    Jeewhizz - MySQL Moderator
    http://www.sitehq.co.uk
    PHP and MySQL Hosting


  •  

    Posting Permissions

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