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 12 of 12
  1. #1
    New Coder
    Join Date
    Feb 2013
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Newby, first gotchme!!

    here is my code:
    Code:
    <html>
    <head>
    	<title>Header</title>
    </head>
    <body>
    <h3>Welcome!</h3>
    	<?
    		echo "<p>Some dynamic output</p>";
    	?>
        <br>
    <p>Some static output here</p>
    </body>
    </html>
    Now here is my output:

    Welcome!

    Some dynamic output
    "; ?>
    Some static output here
    I'm using XAMPP and dreamweaver as an IDE.
    Why am I getting that
    "; ?>
    in my webpage response?

    David.

  • #2
    Regular Coder Redcoder's Avatar
    Join Date
    May 2012
    Location
    /dev/null
    Posts
    335
    Thanks
    2
    Thanked 49 Times in 48 Posts
    Use <?php ..... ?> , <?php echo $var; ?>, <?php $var="string"; ?> instead of the short open tags ( <? ....?>, <? echo $var; ?>, <?="string" ?>. Short open tags look more convenient but they only cause more problems.

    Btw, short open tags will be done away with in PHP 6.

  • #3
    New Coder
    Join Date
    Feb 2013
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Well that didn't work. In fact, i originally had the long tags, but changed it to the short to see if it made any difference.

    Any other ideas? From what I can see, the code looks ok.
    Oh, this document is named as test.html
    I take it it should be with a html suffix and not php, right?
    I'm on win 7.
    I did write a small script with just the php tags and called it test.php and ran that one and that worked ok.

  • #4
    Senior Coder djm0219's Avatar
    Join Date
    Aug 2003
    Location
    Wake Forest, North Carolina
    Posts
    1,312
    Thanks
    4
    Thanked 206 Times in 203 Posts
    Quote Originally Posted by Bucephalus View Post
    Oh, this document is named as test.html
    I take it it should be with a html suffix and not php, right?
    If would have to be .php unless you have your web server configured to treat .html files as php files.
    Dave .... HostMonster for all of your hosting needs

  • #5
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,474
    Thanks
    63
    Thanked 537 Times in 524 Posts
    Name it test.php not .html

    Also call it via your webserver NOT just by double clicking it. EG: http://localhost/test.php
    I can't really think of anything to write here now...

  • #6
    New Coder
    Join Date
    Feb 2013
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by djm0219 View Post
    If would have to be .php unless you have your web server configured to treat .html files as php files.
    Oh yeah, so what file do I need to change?
    I read somewhere that it's like this

    Code:
    # Use PHP5 by default
    AddHandler application/x-httpd-php5 .php
    AddHandler application/x-httpd-php5 .html
    But I just put it in the .htaccess file and that didn't work.
    Which file do I have to put these lines in?
    Dave.

  • #7
    New Coder
    Join Date
    Feb 2013
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by tangoforce View Post
    Name it test.php not .html

    Also call it via your webserver NOT just by double clicking it. EG: http://localhost/test.php
    Thanks, it's working like this, but I would also like to know how to configure my server so that I can use both.
    Does anyone know how to do this? I'm pretty sure it has to be in the .htaccess file but that file doesn't seem to let the server work when I manipulate that file. I'm not sure if it's because I'm using XAMPP and I'm supposed to put it in some other proxy file.

    David

  • #8
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    You can't, or more accurately you do not want to (I'm sure it could be done, but it would be very unwise). File protocol is a filesystem access protocol. If you chain it to webservices for preprocessing, than you will not be able to open files properly. IE: I can open any file on my machine by typing in file://path/to/file.txt, so the last thing I want is to have it intercepted by webservers for preprocessing.
    Always access it through the http protocol or on the command line via php.exe execution.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • #9
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,474
    Thanks
    63
    Thanked 537 Times in 524 Posts
    Quote Originally Posted by Bucephalus View Post
    Oh yeah, so what file do I need to change?
    I read somewhere that it's like this

    Code:
    # Use PHP5 by default
    AddHandler application/x-httpd-php5 .php
    AddHandler application/x-httpd-php5 .html
    But I just put it in the .htaccess file and that didn't work.
    Which file do I have to put these lines in?
    Dave.
    This is what I have - notice the minor differences:

    AddType application/x-httpd-php .html

    Also as Redcoder says, drop the short tags. They were supposed to be a useful thing once but they're a pita as not all servers have them enabled - makes life hell when moving from one server to another. Additionally it also wreaks havoc with any .xml files you also have if .xml is configured to be run by php using the AddType in your .htaccess file.
    Last edited by tangoforce; 02-17-2013 at 08:58 PM.
    I can't really think of anything to write here now...

  • #10
    New Coder
    Join Date
    Feb 2013
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I fixed it. I found this off another forum in a google search.
    I had to change this file in xampp
    \xampp\apache\conf\extra\httpd-xampp.conf
    from:
    <FilesMatch "\.php$">
    to:
    <FilesMatch "\.(php|html)$">

    So that's fixed. My second question would be, are there any dangers to doing this?
    Or do we generally want to make web applications that will use the parsing of php in html files.

    David

  • #11
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,474
    Thanks
    63
    Thanked 537 Times in 524 Posts
    That fix means that your apache / php will now check every file across every directory. That'll grind it down a bit more and imagine what will happen on a live server with thousands of visitors..

    As for the .html thing, yes there is a reason why we don't recommend it. .html is used for static pages that don't change. .php is used for dynamic pages. If you use .html for dynamic then the webserver has to check every .html page for dynamic content which given enough users and connections will grind it down. Thats why we have the .php extension so that you can choose and switch between resource intensive and non resource intensive.

    It's also why it's recommended to use the .htaccess file instead of the main config file for some things because you casn specify different options for different folders. You've just with overkill lol.

    If you really want to hide the use of php then just use folder names and index.php file names to mask it. EG:
    /account/
    /edit/
    /update/

    In each of those folders you have index.php but you never call or link to the php file, just the actual folder. The webserver will serve the index file by default.
    I can't really think of anything to write here now...

  • #12
    New Coder
    Join Date
    Feb 2013
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks Tango.
    I will change it back then since it's not recommended.


  •  

    Posting Permissions

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