Results 1 to 9 of 9
  1. #1
    Join Date
    Aug 2007
    Posts
    905

    PHP source code is showing

    If someone clicks "View Source" it shows the code in <?php ... ?> tags, even the code before <html>

    Is this a problem with how php was configured? I'm using lighttpd, and I followed the guide on the site...

  2. #2
    Join Date
    Jan 2006
    Location
    Athens, Greece
    Posts
    1,479
    Definitely a problem... are you using php in .html pages or .php pages?

  3. #3
    Join Date
    Aug 2007
    Posts
    905
    Oh, it was .html file. My bad...

    Should it still show it though?

  4. #4
    Join Date
    Jan 2006
    Location
    Athens, Greece
    Posts
    1,479
    If it is .html it will show and its parsed as an XML tag I think. If you write it in a .php file it won't.

  5. #5
    Join Date
    Aug 2007
    Posts
    905
    Okay, I thought I did make it .php. Oh well, thanks Steve

  6. #6
    Join Date
    Feb 2003
    Location
    Connecticut
    Posts
    5,441
    If PHP is in an HTML file, it will try to parse it as HTML.. so your code will look like a bunch of gibberish to the end-user

    If you want your HTML files to be parsed as PHP files, you can add the following to your .htaccess file:

    Code:
    AddType application/x-httpd-php .htm .html

  7. #7
    Join Date
    Aug 2007
    Posts
    905
    Cool, thanks for that

  8. #8
    you can set up php/apache to parse .html files for php but it's probably better to use .php for portability.

  9. #9
    Join Date
    Apr 2000
    Location
    California
    Posts
    3,051
    Yes, use .php if you can and never use .html to be parsed as php, shtml or anything else if you can avoid it. If done right, it can be fine, but often this results in files you don't want to have parsed to increase process overhead for no good reason, only for the sake of a few .html files that you do want to have parsed, and it can create security issues if you have anything like a guestbook write to an .html flat file or something of that nature. The reasons are numerous, so don't do it unless you want and need to and have an idea of what you're doing and why, else you can regret it. Just an additional suggestion regarding that.

Posting Permissions

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