Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-17-2013, 12:03 PM   PM User | #1
Bucephalus
New Coder

 
Join Date: Feb 2013
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Bucephalus is an unknown quantity at this point
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.
Bucephalus is offline   Reply With Quote
Old 02-17-2013, 12:20 PM   PM User | #2
Redcoder
Regular Coder

 
Redcoder's Avatar
 
Join Date: May 2012
Location: /dev/couch
Posts: 309
Thanks: 2
Thanked 46 Times in 45 Posts
Redcoder has a little shameless behaviour in the past
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.
__________________
For professional Hosting and Web design.....


NetEssentials.co.uk
Redcoder is offline   Reply With Quote
Old 02-17-2013, 12:29 PM   PM User | #3
Bucephalus
New Coder

 
Join Date: Feb 2013
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Bucephalus is an unknown quantity at this point
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.
Bucephalus is offline   Reply With Quote
Old 02-17-2013, 12:47 PM   PM User | #4
djm0219
Senior Coder

 
djm0219's Avatar
 
Join Date: Aug 2003
Location: Wake Forest, North Carolina
Posts: 1,227
Thanks: 2
Thanked 189 Times in 187 Posts
djm0219 is on a distinguished road
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
djm0219 is offline   Reply With Quote
Old 02-17-2013, 12:52 PM   PM User | #5
tangoforce
Senior Coder

 
tangoforce's Avatar
 
Join Date: Feb 2011
Location: Your Monitor
Posts: 3,516
Thanks: 45
Thanked 440 Times in 429 Posts
tangoforce will become famous soon enoughtangoforce will become famous soon enough
Name it test.php not .html

Also call it via your webserver NOT just by double clicking it. EG: http://localhost/test.php
__________________
Please wrap your code in [php] tags. It is a sticky topic and it HELPS us to HELP YOU!
TIP: Coding styles and $end errors :::::::::: TIP: Warning: Cannot modify header information - headers already sent :::::::::: TIP: Quotes / Parse error: syntax error, unexpected T_..
PHP Code:
//Please don't use this for your form processing:
if (isset($_POST['submit']))
//Internet explorer has a bug and does not always send the submit value. 
Explanation: The IE if(isset($_POST['submit'])) bug explained.
tangoforce is offline   Reply With Quote
Old 02-17-2013, 12:56 PM   PM User | #6
Bucephalus
New Coder

 
Join Date: Feb 2013
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Bucephalus is an unknown quantity at this point
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.
Bucephalus is offline   Reply With Quote
Old 02-17-2013, 01:04 PM   PM User | #7
Bucephalus
New Coder

 
Join Date: Feb 2013
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Bucephalus is an unknown quantity at this point
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
Bucephalus is offline   Reply With Quote
Old 02-17-2013, 04:16 PM   PM User | #8
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,658
Thanks: 4
Thanked 2,451 Times in 2,420 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
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.
__________________
As of PHP 5.5, the MySQL library has been officially deprecated. It is recommended to move to either MySQLi or PDO libraries for your mysql connectivity. See here for help choosing which interface you prefer: http://php.net/manual/en/mysqlinfo.api.choosing.php
Fou-Lu is offline   Reply With Quote
Old 02-17-2013, 07:49 PM   PM User | #9
tangoforce
Senior Coder

 
tangoforce's Avatar
 
Join Date: Feb 2011
Location: Your Monitor
Posts: 3,516
Thanks: 45
Thanked 440 Times in 429 Posts
tangoforce will become famous soon enoughtangoforce will become famous soon enough
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.
__________________
Please wrap your code in [php] tags. It is a sticky topic and it HELPS us to HELP YOU!
TIP: Coding styles and $end errors :::::::::: TIP: Warning: Cannot modify header information - headers already sent :::::::::: TIP: Quotes / Parse error: syntax error, unexpected T_..
PHP Code:
//Please don't use this for your form processing:
if (isset($_POST['submit']))
//Internet explorer has a bug and does not always send the submit value. 
Explanation: The IE if(isset($_POST['submit'])) bug explained.

Last edited by tangoforce; 02-17-2013 at 07:58 PM..
tangoforce is offline   Reply With Quote
Old 02-18-2013, 11:57 AM   PM User | #10
Bucephalus
New Coder

 
Join Date: Feb 2013
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Bucephalus is an unknown quantity at this point
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
Bucephalus is offline   Reply With Quote
Old 02-18-2013, 01:10 PM   PM User | #11
tangoforce
Senior Coder

 
tangoforce's Avatar
 
Join Date: Feb 2011
Location: Your Monitor
Posts: 3,516
Thanks: 45
Thanked 440 Times in 429 Posts
tangoforce will become famous soon enoughtangoforce will become famous soon enough
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.
__________________
Please wrap your code in [php] tags. It is a sticky topic and it HELPS us to HELP YOU!
TIP: Coding styles and $end errors :::::::::: TIP: Warning: Cannot modify header information - headers already sent :::::::::: TIP: Quotes / Parse error: syntax error, unexpected T_..
PHP Code:
//Please don't use this for your form processing:
if (isset($_POST['submit']))
//Internet explorer has a bug and does not always send the submit value. 
Explanation: The IE if(isset($_POST['submit'])) bug explained.
tangoforce is offline   Reply With Quote
Old 02-18-2013, 01:26 PM   PM User | #12
Bucephalus
New Coder

 
Join Date: Feb 2013
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Bucephalus is an unknown quantity at this point
Thanks Tango.
I will change it back then since it's not recommended.
Bucephalus is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 08:11 PM.


Advertisement
Log in to turn off these ads.