Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Mar 2004
    Location
    Milwaukee
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    PHP code appears in HTML source in browser! help!

    I am running apache 2.0.40 on redhat 9, with php 4.2.2. Stock setup.

    The PHP works IF I don't mix any HTML into the code.

    <?php phpinfo(); ?>

    works perfectly, but

    <HTML>
    <HEAD>
    <TITLE>test</TITLE>
    </HEAD>
    <BODY>
    <?php phpinfo(); ?>
    </BODY>
    </HTML>

    or even

    <HTML>
    <?php phpinfo(); ?>
    </HTML>

    does not. If I mix html tags in, and view the page with the browser, I see the line

    <?php phpinfo(); ?>

    in the page source. Is there some setting in php.ini or apache httpd.conf? I have several web servers running the same apache/php configuration, and I've never seen this happen before. It's as if apache isn't recognizing the '<? php' tags..

    As a workaround, we're using echo to output HTML tags, but I should be able to mix up PHP and HTML.

  • #2
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,073
    Thanks
    11
    Thanked 98 Times in 96 Posts
    you have to save your files as .php (or whatever apache is configured to parse) regardless of having HTML content or not , eg if you save them as .html you will get your described issues.
    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)

  • #3
    New to the CF scene
    Join Date
    Mar 2004
    Location
    Milwaukee
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Originally posted by firepages
    you have to save your files as .php (or whatever apache is configured to parse) regardless of having HTML content or not , eg if you save them as .html you will get your described issues.
    The pages are *.php, not *.html.

    In my httpd.conf file there is:

    AddHandler server-parsed .html .php
    XBitHack On

    files are chmod'ed world readable and executable.

  • #4
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,278
    Thanks
    4
    Thanked 83 Times in 82 Posts
    You are probably getting crazy code outputted because the phpinfo() function already outputs all the basic HTML tags like <html> and <body>, etc. That is why is works just fine when you only have that one line in the file like so

    <?php phpinfo(); ?>
    Spookster
    CodingForums Supreme Overlord
    All Hail Spookster

  • #5
    Regular Coder
    Join Date
    Jan 2004
    Location
    Georgia
    Posts
    306
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You might be saving them as .php however, some text editors don't reconize this and save it differently. Try saving it with quotes around the name. Example: "test.php" this will remove the quotes and save it as just test.php. It's worth the try..
    ~Designer's Toolz~


  •  

    Posting Permissions

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