We help IT Professionals succeed at work.

Combining HTML and PHP - How to get Div statement not to show in .html files

497 Views
Last Modified: 2014-08-08
I am trying to create an error message within a a Form when the user enters the wrong Captcha code:

 <?php if(isset($_GET['wrong_code'])){ ?>
 <div style="border:1px solid #990000; background-color:#D70000; color:#FFFFFF; padding:4px; padding- left:6px;width:180px;">Wrong verification code</div><br />
 <?php ;}?>

Another php file sends the result of the captcha code check back in the 'wrong_code' parameter:
CS.html?wrong_code=true

When I save and run the file as a .php file it operates perfectly, however I am stuck using html/htm files (due to many years of Google knowing these files) and the html/htm files show the above error message div upon loading.

I have tried modifying .htaccess by adding various iterations of the statements below to get the html files to act more PHP. This did not work:
AddType application/x-httpd-php .php .html
AddHandler php-script .php .html

I am operating on a form with very little space so I just want an error message that opens up a line under the captcha box in red to tell the user the Captcha code is wrong. I want there to be no error message div shown upon loading and for the error message div to show only if the wrong_code parameter is sent back to the web page. Where am I going wrong? Should I be doing this another way?

All help gratefully appreciated.
Comment
Watch Question

CERTIFIED EXPERT
Expert of the Year 2014
Top Expert 2014

Commented:
Who is your host - some have various techniques to parse html as php

Author

Commented:
Its Digital Pacific in Australia. I shall ask them.
CERTIFIED EXPERT
Expert of the Year 2014
Top Expert 2014

Commented:
It's best as they will know how the server is setup and what directives to use.
(I'm assuming the question was just about getting html parsed as php?)

Author

Commented:
I was hoping to find another way. I only use php in a simple question form in a column on the website.

The host tells me that I can us the following rules:
RewriteEngine On
RewriteBase /
RewriteRule file1.html file1.php
The issue there is that every web page would now have to be processed server-side for a relatively small requirement.

I was hoping there was a simpler way to do display a simple error message without having to go full PHP.
CERTIFIED EXPERT
Expert of the Year 2014
Top Expert 2014

Commented:
That rewrite rule only rewrites that specific page (changing file1.html to your actual page name), not every page, so it is fine to use
You have to use PHP, there is no other way to do server side processing
Fixer of Problems
CERTIFIED EXPERT
Most Valuable Expert 2014
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
Solved the problem
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.