PHP Include not working

Discussion in 'PHP' started by paul_so40, Jan 29, 2011.

  1. #1
    Hey all,

    I have a problem with php include.

    I have the following code in include.php

    <?php
    
    // Gather variable data from the URI
    // eg. filename.php?page=index
    $page = (isset($_GET['page'])) ? $_GET['page'] : 'blog';
    
    // Determine whether or not the requested file exists
    if (!file_exists('includes/' . $page . '.php'))
    {
        echo "File could not be included, no file exists.";
        exit;
    }
    
    switch ($page)
    {
    
        case 'blog':
            include('includes/blog.php');
            break;
       
        // If no variable is set in the URI, or no case matches, include index
        default:
            include('includes/blog.php');
    		break;
    }
    
    ?>
    PHP:

    The i have the following in includes/blog.php

    hello
    PHP:
    but when going to domain.com/include.php?page=blog

    The page loads blank

    Can anyone help with this?

    Thanks
     
    paul_so40, Jan 29, 2011 IP
  2. G3n3s!s

    G3n3s!s Active Member

    Messages:
    325
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    80
    #2
    try
    <?php
    
    // Gather variable data from the URI
    // eg. filename.php?page=index
    $page = (isset($_GET['page'])) ? $_GET['page'] : 'blog';
    
    // Determine whether or not the requested file exists
    if (!file_exists('includes/' . $page . '.php'))
    {
        echo "File could not be included, no file exists.";
        exit;
    }
    
    echo $page;
    
    switch ($page)
    {
    
        case 'blog':
            include('includes/blog.php');
            break;
       
        // If no variable is set in the URI, or no case matches, include index
        default:
            include('includes/blog.php');
            break;
    }
    
    ?>
    PHP:
    and tell us output
     
    G3n3s!s, Jan 29, 2011 IP
  3. paul_so40

    paul_so40 Peon

    Messages:
    119
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    still blank page
     
    paul_so40, Jan 29, 2011 IP
  4. TimK

    TimK Peon

    Messages:
    51
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Try to see if you can catch an error with error reporting.

    
    
    <?php
    error_reporting(-1);
    // Gather variable data from the URI
    // eg. filename.php?page=index
    $page = (isset($_GET['page'])) ? $_GET['page'] : 'blog';
    
    // Determine whether or not the requested file exists
    if (!file_exists('includes/' . $page . '.php'))
    {
        echo "File could not be included, no file exists.";
        exit;
    }
    
    switch ($page)
    {
    
        case 'blog':
            include('includes/blog.php');
            break;
       
        // If no variable is set in the URI, or no case matches, include index
        default:
            include('includes/blog.php');
            break;
    }
    
    ?>
    PHP:

    Also, try making sure that includes/blog.php doesn't have to have specific formatting in order to be displayed by replacing your blog.php with the original.
     
    TimK, Jan 29, 2011 IP
  5. paul_so40

    paul_so40 Peon

    Messages:
    119
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    It turned out it was the file formatting

    Thanks Guys
     
    paul_so40, Jan 29, 2011 IP
  6. G3n3s!s

    G3n3s!s Active Member

    Messages:
    325
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    80
    #6
    File formatting? What does it means?
     
    G3n3s!s, Jan 29, 2011 IP
  7. TimK

    TimK Peon

    Messages:
    51
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #7
    I think he means that the blog.php had to be a certain format to be displayed correctly. I could be wrong but it seems that way.
     
    TimK, Jan 29, 2011 IP
  8. paul_so40

    paul_so40 Peon

    Messages:
    119
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Yh needed to be encoded in utf-8
     
    paul_so40, Jan 29, 2011 IP
  9. G3n3s!s

    G3n3s!s Active Member

    Messages:
    325
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    80
    #9
    you want to tell me it showed you blank page because of bad charset?
     
    G3n3s!s, Jan 29, 2011 IP