A Flash Developer Resource Site

Results 1 to 9 of 9

Thread: Include HTML inside PHP

  1. #1
    Member
    Join Date
    Oct 2007
    Posts
    81

    Include HTML inside PHP

    Hi guys.

    So I created a sidebar (sidebar.html), my sidebar is in html and I want to include it to my footer.php file.

    First of all you cant include an html file using
    PHP Code:
    include 'sidebar.html'
    (at least it doesn't work for me..)
    But thats okay, I could use numbers of other codes, but I cant since I have another function, here is my function;

    PHP Code:
        <?php 
        
    if (isLoggedIn() == true)         
        <
    link rel="text" type="text" href="sidebar.html" />
        
    ?>


    This mean that I only want to show the sidebar if the user is logged in, probably you all noticed that, but its better be specific than let people wonder..:P

    When I use this code I get unexpected '<'

    I also tried;

    PHP Code:
    <?php 
    if (isLoggedIn() == true)
    {
    ?>
    <link rel="text" type="text" href="sidebar.html" />
    <?php
    }
    ?>
    Then I get not error, but the file isn't included either :S

    Is there other ways I could include this file? I still want it to be shown only if logged in too...

  2. #2
    AS3 Mod
    Join Date
    Sep 2007
    Location
    O-H-I-O
    Posts
    2,385
    Actually you CAN include an .html file like you have in your first example. Something else must be wrong with your code.

  3. #3
    Member
    Join Date
    Oct 2007
    Posts
    81
    Well... Heres my code;

    PHP Code:
    <?xml version="1.0" encoding="iso-8859-1"?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

    <head>

        <title>My Sidebar</title>

        <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />


        



        <!-- Docking boxes (dbx)  -->
        <script type="text/javascript" src="functions/dbx.js"></script>

        <!-- dbx configuration script -->
        <script type="text/javascript" src="functions/dbx-key.js"></script>

        <!-- dbx stylesheet -->
        <link rel="stylesheet" type="text/css" href="stylesheet.css" media="screen, projection" />





        

    </head>

    <body>





        <div id="purple-outer">

            <div class="dbx-group" id="purple">


            <div class="dbx-box">

                <h3 class="dbx-handle" title="Example1">Example1</h3>

                <ul class="dbx-content">
                    <li><a href="/example2/">Example2</a></li>
                    <li><a href="/example3/">Example3</a></li>
                    <li><a href="/example4/">Example4</a></li>
                    <li><a href="/example5/">Example5</a></li>
                </ul>

            </div>




                <div class="dbx-box">

                    <h3 class="dbx-handle" title="Example6">Example6</h3>

                    <ul class="dbx-content">
                        <li><a href="/example7/">Example7</a></li>
                        <li><a href="/example8/">Example8</a></li>
                        
                    </ul>

                </div>


                


            </div>

        </div


    </body>
    </html>
    And it works as it suppose to... Nothing wrong on it.

  4. #4

  5. #5
    Member
    Join Date
    Oct 2007
    Posts
    81
    Oh sorry..
    Here;
    PHP Code:
    </div>
            <div id="secondaryContent">
    <?php
        
    if (isLoggedIn() == true)         
    //Here goes the include code im looking for   

        
    ?> 

                    </div>
            </div>
                    </div>
                    </div>
        <div id="footer">
            <ul>
                
    <br>
    &copy; 2008 
                
            </ul>
        </div>
    </body>
    </html>

  6. #6
    Bearded (M|G)od MyFriendIsATaco's Avatar
    Join Date
    Dec 2002
    Location
    Awesomeville.
    Posts
    3,045
    You should have no problem with:
    PHP Code:
    <?php
        
    if (isLoggedIn() == true)
            include 
    'sidebar.html';
    ?>
    Are you sure your isLoggedIn() function is returning true?

  7. #7
    Member
    Join Date
    Oct 2007
    Posts
    81
    It worked with a more simpler sidebar... but not with this one, no its just returning blank, no errors, nothing...

  8. #8

  9. #9
    Bearded (M|G)od MyFriendIsATaco's Avatar
    Join Date
    Dec 2002
    Location
    Awesomeville.
    Posts
    3,045
    I have a feeling that it has to do with your <?xml declaration. <? is an entry PHP tag, so it may be trying to parse the whole page as a block of PHP code.

    For your sidebar.html page, you shouldn't even be having the whole page declaration and whatnot because the code will already exist on the page.

Posting Permissions

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




Click Here to Expand Forum to Full Width

HTML5 Development Center