Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PHP Input problem 1

Status
Not open for further replies.

Domino2

Technical User
Jun 8, 2008
475
GB
I have two questions. Can a page with a .htm extension have PHP working on it. I thought if I put:

<?php
session_start();
?>


<html>

In the code, PHP knew there would be PHP on the page. Correct??

My second question is I have a page of input boxes on a form that will be filled from a query. I am using this code in the HTML, but it displays the PHP expression?

<input name="AA" value="<? =$_SESSION['AA'] ?>" size="22"></font></td>

Many thanks

 
question 1.
only if you have told your webserver to send all htm pages through the php sapi/cgi

probably the answer is the same as q1. but in any event your syntax is wrong

Code:
<input name="AA" value="<?=$_SESSION['AA'] ?>" size="22"></font></td>
will work (note no space) if you have short tags turned on. otherwise
Code:
<input name="AA" value="<?php echo $_SESSION['AA']; ?>" size="22"></font></td>

is what you want.
 
Many thanks jpadie, fixed nicely. Ref question 1, I am using a wampserver on my pc. I tried changing the extension from .php to .html, but the PHP coding became visible in the input box. So I guess somewhere there is a setting change to be done in the server software. It's not so important as it can stay a PHP page.
 
there will be a file called httpd.conf somewhere in your wamp installation. find that file and edit it

within the file you will find a line that says something like

Code:
AddType application/x-httpd-php .php

just add htm and html after

code]
AddType application/x-httpd-php .php [red].html .htm .phtml[/red[
[/code]

save the file and restart the webserver. apache will then send html and htm files via php
 
Many thanks. I found 2 files, one ending config the other config/original. I added your line into the presumeably real one not /original list as:

AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
AddType application/x-httpd-php .php
AddType application/x-httpd-php .php3

AddType application/x-httpd-php .php [red].html .htm .phtml[/red[

Although I think I should have removed the 3rd one down.

In the one ending/original, it has only one entry:

AddType application/x-gzip .gz .tgz

Regards



 
should look like this
Code:
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
AddType application/x-httpd-php .php .php3 .htm .html .phtml
 
Just a word of caution though. This kind of practice is not something Web hosts normally do. So if you decide to upload your pages to a Web host or online server for use on the internet you'll find they no longer work because the server will not be configured to send HTM and HTML pages through the PHP CGI.

Just keep that in mind.

----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top