CodingForums.com

CodingForums.com (http://www.codingforums.com/index.php)
-   PHP (http://www.codingforums.com/forumdisplay.php?f=6)
-   -   Newby, first gotchme!! (http://www.codingforums.com/showthread.php?t=287780)

Bucephalus 02-17-2013 12:03 PM

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:

Quote:

Welcome!

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

"; ?>
in my webpage response?

David.

Redcoder 02-17-2013 12:20 PM

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.

Bucephalus 02-17-2013 12:29 PM

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.

djm0219 02-17-2013 12:47 PM

Quote:

Originally Posted by Bucephalus (Post 1313909)
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.

tangoforce 02-17-2013 12:52 PM

Name it test.php not .html

Also call it via your webserver NOT just by double clicking it. EG: http://localhost/test.php

Bucephalus 02-17-2013 12:56 PM

Quote:

Originally Posted by djm0219 (Post 1313914)
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.

Bucephalus 02-17-2013 01:04 PM

Quote:

Originally Posted by tangoforce (Post 1313915)
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

Fou-Lu 02-17-2013 04:16 PM

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.

tangoforce 02-17-2013 07:49 PM

Quote:

Originally Posted by Bucephalus (Post 1313917)
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.

Bucephalus 02-18-2013 11:57 AM

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

tangoforce 02-18-2013 01:10 PM

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.

Bucephalus 02-18-2013 01:26 PM

Thanks Tango.
I will change it back then since it's not recommended.


All times are GMT +1. The time now is 07:53 AM.

Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.