Link to home
Start Free TrialLog in
Avatar of ddantes
ddantesFlag for United States of America

asked on

Converting html with php to pure php

My web host's server is having trouble parsing php code within html pages, so I'd like to convert such a page to pure php.  I've tried various online, automated html-to-php converters, but the resulting page has no styling.  Please advise.
 contact.htm
Avatar of Dave Baldwin
Dave Baldwin
Flag of United States of America image

There would be no point.  The first 4 lines are the ONLY PHP code on that page.
Avatar of ddantes

ASKER

Thank you Dave.  The purpose of the conversion is to avoid presenting the server with php code within an html file.  The server can't parse that code, even when htaccess should allow it.  The web host asked me if I can reproduce that page with no html, just php.
That's dumb.  Change the name to 'contact.php' and be done with it.
Does the .htaccess file is in the same directory?

AddHandler application/x-httpd-php .html

Open in new window

inside the .htaccess file.
The .htaccess file must be in the same directory with your html file.
Avatar of ddantes

ASKER

Thank you both.  I'll post again after testing...
Who is the web host?  I think based on what is requesting that is what should be changed.

Anyway, consider this simple example.
</php
echo "<p>Hello World</p>";
?> 

Open in new window

This is actually no different than
<p>Hello World</p>

Open in new window

In your case, you can do as Dave suggests and change the name to php. Additionally place all the html in php like
<?php
$html= <<<EOD
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>Contact Maui Tradewinds</title>
<meta name="robots" content="noindex, nofollow">
<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/jquery.easing.min.js"></script>		
<script type="text/javascript" src="js/minmax.js"></script>
<script type="text/javascript" src="p7ehc/p7EHCscripts.js"></script>
<script type="text/javascript" src="p7dmm/p7DMMscripts.js"></script>
<script type="text/javascript" src="js/GA.js"></script>
<link href="p7dmm/p7DMM01.css" rel="stylesheet" type="text/css" media="all">
<link href="p7affinity/p7affinity-1_01.css" rel="stylesheet" type="text/css">
<link href="p7affinity/p7affinity_print.css" rel="stylesheet" type="text/css" media="print">
<link rel="stylesheet" href="p7affinity/global_css.css" type="text/css" media="screen">

<script src="js/detect-smartphone.js" type="text/javascript"></script>
<script type="text/javascript">
if(IsSmartPhone()){
   location.replace("m_contact.htm");}
</script> 
<style type="text/css">







.honey{
position: absolute !important;
top: -9999px !important;
left: -9999px !important;
}

.formlabel {    
    display: block;
    white-space:nowrap;
    margin-left:-10px !important;
    text-align:right;
    font-size:1em;     
    width:99%;
}

.fullfld {
width:30%; 
padding:5px; 
}
    
input[type=text]{
    color:blue;
    height: 20px;
    width:20%;
    font-size:medium;	
}
</style> 

<!--[if lte IE 7]>
<style>

body {min-width: 1020px;}
.columns-wrapper, .menu-top-wrapper, .p7dmm-sub-wrapper {width: 980px;}
</style>
<![endif]-->
</head>
<body>
<!-- Start eXTReMe Pro Tracker Code V3/7
Login:    tradewds
Help:     https://www.extremetracking.com
Installation instructions:
Copy and paste this code between the two body tags into the
*source* of your pages or in your footer/template. Best is
to use a normal text editor such as notepad. -->
<script type="text/javascript"><!--
EXd=document;location.protocol=="https:"?EXp="https":EXp="http";EXs="src";
EXd.write("<img "+EXs+"="+EXp+"://nht-2.extreme-dm.com/n2.g?login=tradewds",
"&url="+escape(EXd.URL)+"&jv="+navigator.javaEnabled()+"&",
"d="+screen.width+"x"+screen.height+"&c="+screen.colorDepth+"",
"&l="+escape(EXd.referrer)+" width=0 height=0>");//-->
</script>
<noscript><img height="1" width="1" alt="" src="http://nht-2.extreme-dm.com/n2.g?login=tradewds&amp;url=nojs"></noscript>
<!-- End eXTReMe Pro Tracker Code -->
<div class="masthead" style="margin-right:5px; text-align:center">
<img id="logo1" src="images/contact-logo.png" alt="Maui Tradewinds  4320 Une Pl.  Haiku, HI 96708" class="scalable"> 

<img src="images/contact-title.png" alt="" class="scalable">

</div>
<div class="top-navigation"> 
<div class="menu-top-wrapper">
<div id="p7DMM_1" class="p7DMM01 p7DMM p7dmm-left responsive">
<div id="p7DMMtb_1" class="p7DMM-toolbar"><a href="#" title="Hide/Show Menu"><img src="p7dmm/img/toggle-icon.png" alt="Toggle Menu"></a></div>
<ul id="p7DMMu_1" class="p7DMM01-menu">
<li><a id="p7DMMt1_1" href="index.htm">HOME</a></li>
<li><a href="suite.htm">SUITE</a></li>
<li><a href="StarWind.htm">COTTAGE</a></li>
<li><a id="p7DMMt1_4" href="viewtriage.htm" target="_blank">THE VIEW</a></li>
<li><a id="p7DMMt1_5" href="https://www.tripadvisor.com/Hotel_Review-g60629-d1566384-Reviews-Maui_Tradewinds-Haiku_Maui_Hawaii.html" target="_blank">REVIEWS</a></li>
<li><a id="p7DMMt1_6" href="RezEasy/availability.html" target="_blank">RATES &amp; CALENDAR</a></li>
<li><a id="p7DMMt1_7" href="location.htm">LOCATION</a></li>
<li><a id="p7DMMt1_8" href="service.htm">AMENITIES</a></li>
<li><a id="p7DMMt1_9" href="hostess.htm">HOSTS</a></li>
<li><a id="p7DMMt1_10" href="contact.htm">CONTACT</a></li>
<li><a id="p7DMMt1_11" href="links.htm">LINKS</a></li>
<li><a id="p7DMMt1_12" href="Attractions.htm">ATTRACTIONS</a></li>
</ul>
<script type="text/javascript">P7_opDMM('p7DMM_1',3,450,0,1,1,1,1,0,1);</script>
</div>
</div>
</div>  
          
 <div class="content-wrapper">
  <div class="columns-wrapper">
    <div class="main-content">
      <div class="content p7ehc-1">

<h1 style="text-align:center; color:blue">How can we be of Service?</h1>
<p style="text-align:center">Please fill in the fields below.  At a minimum, your full name, Email address and a message are required, in order to submit the form.<br>
Alternatively, you're welcome to call us at (808) 573-0066<br>or toll-free from U.S. at (800) 909-6774, 
or <a href="mailto:stay@mauitradewinds.com">Email us</a>.<br>
This form is for inquiries from prospective guests. We don't respond to advertisements for products or services, and we report spam to the Federal Trade Commission (spam@uce.gov)</p>
<br><br>
<form method="POST" name="contactform" id="contactform" action="contact-form-handler.php">
<p class="formlabel">
First Name:
<input type="text" class="fullfld" style="margin-right:20px" maxlength="30" name="firstname">
Last Name:
<input type="text" class="fullfld" style="margin-right:20px" maxlength="40" name="lastname">
Address:
<input type="text" class="fullfld" maxlength="70" name="Address">
</p>

<p class="formlabel">
City:
<input type="text" class="fullfld" style="margin-left:47px; margin-right:60px" maxlength="30" name="City">
State:
<input type="text" class="fullfld" style="margin-right:50px" maxlength="30" name="State">
Zip:
<input type="text" class="fullfld" maxlength="15" name="Zip">
</p>

<p class="formlabel">
Country:
<input type="text" class="fullfld" style="margin-left:20px; margin-right:20px" maxlength="15" name="Country">	
Telephone:
<input type="text" class="fullfld" style="margin-right:36px" maxlength="30" name="Phone">
Email:
<input type="text" class="fullfld"  maxlength="80" name="email">
</p>
<h3 style="text-align:center; color:black">Enter your message in the box below:</h3>
<textarea cols="60" rows="5" name="message" style="display:block; margin: 0 auto; width:50%; padding:3px; overflow:hidden; font-size:16px"></textarea>
<br><h3 style="text-align:center" class="honey">Full Name:</h3>
<textarea cols="60" rows="5" name="name" class="honey"></textarea>
<br><br>
<button type="submit" id="submit" disabled style="display:block; margin:auto; width:15%">Submit Form</button>
</form>
<script type="text/javascript" src="js/contact.js"></script>
<script type="text/javascript" src="js/contactformvalidator.js"></script>

      <br>
<div style="text-align:center;">
<ul class="blocks blocks-four-up">
		<li>
			<div class="blocks-inner">
                <div>
              &nbsp;</div>
             </div>
		</li>
		<li>
			<div class="blocks-inner">
                <div>
              <img src="images/TripAdvisor-Certificate-of-Excellence.jpg" alt="TripAdvisor Certificate of Excellence" width="98" height="77">
                </div>
             </div>
		</li>
				<li>
			<div class="blocks-inner">
                <div>
              <img src="images/MCCmemb.gif" alt="Member, Maui Chamber of Commerce" width="100" height="100">
                </div>
             </div>
		</li>
		<li>
			<div class="blocks-inner">
                <div>
              &nbsp;</div>
             </div>
		</li>
</ul>
</div>
      </div>
    </div>
  </div>
</div>
<div style="text-align:center">
	<a href="https://www.facebook.com/Mauitradewinds" target="_blank"><img alt="" height="60" src="images/SocialMediaImages/Facebook.png" width="60"></a>&nbsp;&nbsp;
	<a href="https://www.google.com/maps/place/Maui+Tradewinds,+4320+Une+Pl,+Haiku,+HI+96708,+United+States/@20.916452,-156.284313,17z/data=!4m2!3m1!1s0x7eab350296215b03:0xef284bc45ffaaf1e" target="_blank"><img alt="" height="60" src="images/SocialMediaImages/Google+.png" width="60"></a>&nbsp;&nbsp;
	<a href="https://www.pinterest.com/mauitradewinds/" target="_blank"><img alt="" height="60" src="images/SocialMediaImages/Pinterest.png" width="60"></a>&nbsp;&nbsp;
	<a href="https://www.tripadvisor.com/Hotel_Review-g60629-d1566384-Reviews-Maui_Tradewinds-Haiku_Maui_Hawaii.html" target="_blank"><img alt="" height="60" src="images/SocialMediaImages/TripAdvisor.png" width="60"></a>&nbsp;&nbsp;
	<a href="https://mobile.twitter.com/ddantes4320" target="_blank"><img alt="" height="60" src="images/SocialMediaImages/Twitter.png" width="60"></a>&nbsp;&nbsp;
	<a href="http://www.yelp.com/biz/maui-tradewinds-haiku-2" target="_blank"><img alt="" height="60" src="images/SocialMediaImages/Yelp!.png" width="60"></a>
</div>

<div class="footer">
    <p class="copyright">Website created and maintained by David Dantes. Text, photographs and graphics (except HVCB, TripAdvisor, MVRA, MCC and MVB logos, Hawaii State and Maui County emblems) are Copyright &#169; 1998-2018 David Dantes "Maui Tradewinds" Reg. U.S. Pat. &amp; Tm. Off.</p>
  </div>
</body>
</html>
EOD;

echo $html;
?>

Open in new window

Avatar of ddantes

ASKER

I appreciate having that code.  However, the contact form handler is not working with the contact form, as it did when the form was html.  I am not receiving the contact form by Email after it is submitted.  If you're willing, I uploaded both the form and form handler.  On the form, I added code which establishes a session, since that is required before the form handler will transmit the form by Email.

contact.phpcontact.php
contact-form-handler.php
It's already been mentioned, but trying to wrap all your HTML up in a PHP tag just makes no sense at all. Give both your files the php extension and then code your HTML as you normally would and your PHP as you normally would.

Trying to go against the standard way of doing things and getting 'creative' will just lead to more problems than it solves.

I would suggest cleaning up your contact.php page - well structured, clean HTML makes for an easier life. As for your contact form handler, that definitely needs cleaning up. All that spam protection you've got in place is pretty useless.

For debugging purposes, always start your script with the following:

<?php 
error_reporting(E_ALL);
ini_set('display_errors', 1);

Open in new window


Now you'll get some proper error message showing up if there's a problem. And while you're testing, var_dump out your POST array so you can see what's being sent from the form:

var_dump($_POST);

And if you really want to step it up a level, consider using PHPMailer instead of the built in mail() function. Much more flexible and robust.
Avatar of ddantes

ASKER

Thank you.  I added the error reporting code to the form handler.  The form was not transmitted, but I did not see any error reported.  Will the error appear as a popup, or where should I look for it?
Just my two cents - I'd favor the recommendation of renaming the file to end with contact.php unless you have a LOT of search engine and bookmark traffic that is going to the old URL with "contact.htm."

The first reason for this is that an HTML file (.htm or .html) is static (it doesn't change), and static files are GREAT when you can use them because there is no special handling for them - the web server simply grabs the file and sends the contents back to the browser, and it can all be done in a handful of microseconds.

If the web server is told to give the file to the PHP engine for extra processing before it can be sent back, then suddenly the PHP engine enters the picture and starts eating up valuable resources like extra memory and CPU, even if there isn't any PHP code to process.

It's the equivalent of turning on the oven in your kitchen every time you want to cook something. Many times, you won't need the oven, so turning it on is wasteful unless the recipe calls for something to be put into that oven.

It's presumable that you have lots of .htm files on your site that don't have any PHP code in them, so trying to tell the web server to give .htm files to the PHP engine to be processed means that you're running the PHP engine all the time for files that don't have any PHP code.

If you just rename the file to contact.php and don't add any special configuration to your .htaccess file, then your .htm files can continue to be served up lightning-fast, while the contact.php file can be properly handled by the PHP engine.

Plus, this makes it easier for you to determine which files actually have PHP code and which are just plain HTML files. Most developers assume that if they see a ".htm" or ".html" extension, it's a static HTML file.

So while adding the PHP handler to .htm files might be a quick fix, it's probably not as good as renaming the file if that's possible.

Again, the only reason NOT to rename the file is if you've already built up a lot of SEO / external links to "contact.htm" and you don't want any impact at all to it. And even then, you can use "301" redirects to minimize the impact.
Avatar of ddantes

ASKER

Thank you.  I did follow that advice, and renamed the contact file .php.  I also removed the special configuration code from htaccess.  However, the contact form handler is not delivering the contact form by Email as it used to do.
Is the contact form getting past the session check?

You should also change this line in your handler:
      mail($to,$email_subject,$email_body,$headers);

...to check for errors:

if(!mail($to,$email_subject,$email_body,$headers))
{
  $errors .= "\nThe mail() call failed: " . error_get_last()['message'];
}
Avatar of ddantes

ASKER

Thanks to all Experts.  I don't see a way to award assisted solutions, so I could only designate the best solution, but every comment was helpful.  My web host thinks the contact form handler isn't working because he needs to make an adjustment on the Email server.
>  I don't see a way to award assisted solutions

You should be able to click, "This solved my problem" on any comment to award points.
ASKER CERTIFIED SOLUTION
Avatar of ddantes
ddantes
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Wasn't the point of unaccepting the solution so the OP could select multiple solutions that helped?
Avatar of ddantes

ASKER

Maybe I don't understand how this works.  The question was re-opened so that I could acknowledge multiple helpful contributions, and I marked four comments as helpful.  The actual solution was self-provided.  Am I missing something?
Several people, including myself, described the server configuration issue and talked about various ways to overcome it. Pretty much everyone that suggested renaming the file to .php was recognizing the problem and pointing it out.

For example, my entire comment in the middle of this discussion was specifically about the server configuration, having files processed by the PHP engine, and best practices (as opposed to quick fixes).

If you didn't have to change any code or rename any files, then you probably got a quick fix (which is not really the right way to solve the problem), which is exactly what I described here:
So while adding the PHP handler to .htm files might be a quick fix, it's probably not as good as renaming the file if that's possible.

Adding the PHP handler to handle .htm files is the Apache configuration change that would be done to make this work without renaming the file. And like I said, that's really not the right way to do it.

I honestly don't care as much about the points as I do about you not going down a path that will cause you performance problems in the future.
Avatar of ddantes

ASKER

Thank you.  My web host manages the server configuration. This task is beyond my expertise, and I don't have access to the Apache server system.  Whatever adjustment he made, the contact forms have worked perfectly since then.  

Based the wording of the message you posted two hours ago, your concern was that the question had been re-opened for the purpose of acknowledging multiple comments as helpful.  That led me to wonder if I was missing something, because I did use the opening to acknowledge multiple contributions.   Here is a screen shot showing that your comment was included among those marked as helpful...User generated image  I hope this, along with the fact that the server configuration has been adjusted, addresses your concerns.
Ah, I just noticed that there was some recent change to how assisted solutions are marked. It used to show a green "Assisted Solution" flag on those marks, but now it's just a light-grey "Helpful" box near the corner. My apologies.
Avatar of ddantes

ASKER

No worries.  I have difficulty adjusting to those changes, if I even notice them.
@gr8gonzo - pretty sure questions can have an accepted solution, assisted solutions AND helpful comments. Haven't asked a question in ages, but it seems the new system is causing some confusion with Askers. I've seen quite a few comment of late stating that people aren't sure how to close questions anymore. It used to be so simple !!