Very basic php not working?

Discussion in 'PHP' started by Spider-Man, Mar 4, 2008.

  1. #1
    Hey. I haven't done much php work - so am quite confused as to why this code doesn't work, here's an example:


    Inside example.html, instead of having the footer coded in html, I want it so I only ever have to edit 1 file - the php file.

    So I have this code in example.html

    <div class="footer">
    <?php include('footer.php'); ?>
    </div>
    Code (markup):
    In footer.php, I have this:
    <p><a href="link1.html">Link 1</a> | <a href="link2.html">Link 2</a> | <a href="link3.html">Link 3</a> </p>
    Code (markup):
    I have uploaded both files to the server - however, where the footer should appear, I just get a white blank space...

    Does anyone have any idea why it's not working?


    Thanks!
     
    Spider-Man, Mar 4, 2008 IP
  2. Vbot

    Vbot Peon

    Messages:
    107
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #2
    You can't have php inside .html page, unless you set your server to handle html as php. What you can do is rename your example.html to example.php then it will work.
     
    Vbot, Mar 4, 2008 IP
  3. shallowink

    shallowink Well-Known Member

    Messages:
    1,218
    Likes Received:
    64
    Best Answers:
    2
    Trophy Points:
    150
    #3
    Is the file in the same directory?
    doh, good catch vbot, I didn't even look at the filename.
     
    shallowink, Mar 4, 2008 IP
  4. Spider-Man

    Spider-Man Banned

    Messages:
    2,684
    Likes Received:
    211
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Ah, okay. The file is in the same directory.

    So how do I get my server to handle php as html or vice versa?

    Thanks :)
     
    Spider-Man, Mar 4, 2008 IP
  5. spdev

    spdev Peon

    Messages:
    65
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    check you file calling footer.php is in the same directory as it and also that the file calling footer is a .php
    another thing to check would be permissions, this can sometimes stop you from "including" other files.
     
    spdev, Mar 4, 2008 IP
  6. proxywhereabouts

    proxywhereabouts Notable Member

    Messages:
    4,027
    Likes Received:
    110
    Best Answers:
    0
    Trophy Points:
    200
    #6
    to handle php as html, you need to have mod_rewrite on your server and make use of CRR on your htaccess.
     
    proxywhereabouts, Mar 4, 2008 IP
  7. shallowink

    shallowink Well-Known Member

    Messages:
    1,218
    Likes Received:
    64
    Best Answers:
    2
    Trophy Points:
    150
    #7
    Just change the file from example.html to example..php. Your webhost should support PHP files without any additional effort. Try it.
     
    shallowink, Mar 4, 2008 IP
  8. Vbot

    Vbot Peon

    Messages:
    107
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #8
    So you still want to use .html instead of rename it to php?
    if so, create a .htaccess file in the same directory and paste this code in.

    AddType application/x-httpd-php .html
    Code (markup):
     
    Vbot, Mar 4, 2008 IP
  9. Spider-Man

    Spider-Man Banned

    Messages:
    2,684
    Likes Received:
    211
    Best Answers:
    0
    Trophy Points:
    0
    #9
    Hello. The server is a Linux server, and supports .htaccess, I have added the line

    AddType application/x-httpd-php .html
    Code (markup):
    to the .htaccess file, but now when I try to navigate to example.php - firefox pops up the download box as if it is downloading the example.html file to my computer...

    :confused:
     
    Spider-Man, Mar 4, 2008 IP
  10. shallowink

    shallowink Well-Known Member

    Messages:
    1,218
    Likes Received:
    64
    Best Answers:
    2
    Trophy Points:
    150
    #10
    Man, just change the file extension to .php. You don't need to make .html parsed as PHP for the whole site. Its overkill. Best delete that line.
     
    shallowink, Mar 4, 2008 IP
  11. Vbot

    Vbot Peon

    Messages:
    107
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #11
    Oops then change it to:
    
    AddType application/x-httpd-php .php .html
    
    Code (markup):
     
    Vbot, Mar 4, 2008 IP
  12. Spider-Man

    Spider-Man Banned

    Messages:
    2,684
    Likes Received:
    211
    Best Answers:
    0
    Trophy Points:
    0
    #12
    Are you suggesting I change all pages to .php - wouldn't this mean I have to recode the entire site?

    Thanks
     
    Spider-Man, Mar 4, 2008 IP
  13. shallowink

    shallowink Well-Known Member

    Messages:
    1,218
    Likes Received:
    64
    Best Answers:
    2
    Trophy Points:
    150
    #13
    Are you doing your entire site over? You can do it pretty easily without changing webserver settings. And its the first I have seen you mention doing the entire site. The first post was "why isn't this working with one file".
     
    shallowink, Mar 4, 2008 IP
  14. Spider-Man

    Spider-Man Banned

    Messages:
    2,684
    Likes Received:
    211
    Best Answers:
    0
    Trophy Points:
    0
    #14
    Hey. I am just starting the site. Got around 14 pages done - using html, fully x-html/css compliant.

    What's your idea?

    Cheers :)
     
    Spider-Man, Mar 4, 2008 IP
  15. Vbot

    Vbot Peon

    Messages:
    107
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #15
    Did you get my last post? does it fix your problem yet?
     
    Vbot, Mar 4, 2008 IP
  16. Spider-Man

    Spider-Man Banned

    Messages:
    2,684
    Likes Received:
    211
    Best Answers:
    0
    Trophy Points:
    0
    #16
    No, unfortunately not :(

    When I go to index.html - Firefox pops up the download box and asks me to open/save the index.html file, it is the same for every file.

    Ahh, this sucks :(
     
    Spider-Man, Mar 4, 2008 IP
  17. shallowink

    shallowink Well-Known Member

    Messages:
    1,218
    Likes Received:
    64
    Best Answers:
    2
    Trophy Points:
    150
    #17
    Well you are putting the nav links to a php include file right? Do you have lots of other links internally? Have you already edited the files to add those?

    Vbot's suggestion above for the AddType should have worked though.
     
    shallowink, Mar 4, 2008 IP
  18. Vbot

    Vbot Peon

    Messages:
    107
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #18
    I edited the code to include .php and .html I guess you didn't notice that eh.
     
    Vbot, Mar 4, 2008 IP
  19. Spider-Man

    Spider-Man Banned

    Messages:
    2,684
    Likes Received:
    211
    Best Answers:
    0
    Trophy Points:
    0
    #19
    Yeah, it should have worked for AddType - but it doesn't :(

    Should I just go round changing every instance of .html to .php?

    Thanks
     
    Spider-Man, Mar 4, 2008 IP
  20. Spider-Man

    Spider-Man Banned

    Messages:
    2,684
    Likes Received:
    211
    Best Answers:
    0
    Trophy Points:
    0
    #20
    Yes, I did change it again and I get the same problem. If I save the file as .php it works, but not as .html ?

    When it is .html, firefox asks me to open or save the file on my computer, not on the server. Meh :(
     
    Spider-Man, Mar 4, 2008 IP