Web Analytics Made Easy -
StatCounter Dynamic includes? - CodingForum

Announcement

Collapse
No announcement yet.

Dynamic includes?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new 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
    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; Jul 9, 2002, 02:55 PM.
    I don't suffer from insanity, I enjoy every single minute of it!

    Comment


    • #3
      Thanks Worked perfectly

      Comment


      • #4
        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)

        Comment


        • #5
          It does work... I completely sympathise with your confusion here...

          Comment


          • #6
            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.

            Comment


            • #7
              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

              Comment

              Working...
              X