Page 1 of 1

PHP include function doesn't work in HTML file

Posted: Sun Apr 11, 2010 2:40 pm
by loweauto
I am trying to implement a contact form, and the instructions to do so are found here: http://westworldvideos.com/contact/help/

I cannot get past the first step: "Include the 'contact-script.php' file in the page area where you want to see the contact form."

It tells me to use the following code:

Code: Select all

<?php
include '/path/to/public_html/yourwebsite.com/contact-script.php';
?>
But I'm not sure if this is right. What is that "/path/to/public_html/" part?

The way my site works is like this:

index.php file opens a layout.html file, where there's an include to include the content depending on "index.php?go=contact", for example, and the contact.html resides in root/html/contact.html, and it's just the sheer content. Perhaps this is causing the problem?

This is index.php for your interest:

Code: Select all

<?php 

$go = "index" ; 

if ($_GET["go"])
	$go = $_GET["go"] ;

$body = "html/{$go}.html" ;
$head = "html/_{$go}.html" ;

if (!file_exists($body)) {	
	$body = "html/index.html" ; 
}

if (!file_exists($head)) {
	$head = "html/_index.html" ;
}

$CONTENT = implode('', file($body)) ;
$HEAD = implode('', file($head)) ;
	
include "layout.html" ;

?>
As you noticed, the contact.html I'm trying to implement the php code in isn't a .php file, but I have added the following into htaccess, and it works to put php in other html files:

Code: Select all

RemoveHandler .html .htm
AddType application/x-httpd-php .php .htm .html
What do you think the problem is?

I hope to hear from you![/php]

As you noticed, the contact.html I'm trying to implement the php code in isn't a .php file, but I have added the following into htaccess, and it works to put php in other html files:

[text]RemoveHandler .html .htm
AddType application/x-httpd-php .php .htm .html[/text]

What do you think the problem is? To outline it again, the problem is that this code isn't working - there's nothing in the browser.

I hope to hear from you!


P.S. I changed the code to:

<?php include("contact-script.php"); ?>

And now it appears in the source code in the browser!

Re: PHP include function doesn't work in HTML file

Posted: Sun Apr 11, 2010 4:30 pm
by Robert07
Hello,
It sounds like you are confusing yourself. Anyway, the /path/to/public_html means you should put the path to your webroot there. Or you could use a relative link instead like you tried in the PS.

If you include a php file with php code into an html file I can't imagine that would work. You'll need to change your layout.html to layout.php and possibly your contact.html to contact.php. That should help.
Regards,
Robert

Re: PHP include function doesn't work in HTML file

Posted: Sun Apr 11, 2010 4:33 pm
by loweauto
Robert07 wrote:Hello,
It sounds like you are confusing yourself. Anyway, the /path/to/public_html means you should put the path to your webroot there. Or you could use a relative link instead like you tried in the PS.

If you include a php file with php code into an html file I can't imagine that would work. You'll need to change your layout.html to layout.php and possibly your contact.html to contact.php. That should help.
Regards,
Robert
but i changed the htaccess to allow php to be executed in html files.. i thought then it's meant to work?

Re: PHP include function doesn't work in HTML file

Posted: Sun Apr 11, 2010 4:55 pm
by Robert07
I believe the trouble is that the include is executed, but the included code is not, which is why it's in the page source. It's a subtle difference, but it does seem to be acting like the code is being included without the surrounding php tags.

Re: PHP include function doesn't work in HTML file

Posted: Sun Apr 11, 2010 5:22 pm
by loweauto
Robert07 wrote:I believe the trouble is that the include is executed, but the included code is not, which is why it's in the page source. It's a subtle difference, but it does seem to be acting like the code is being included without the surrounding php tags.
not sure what you mean, so ur saying that the code that's showing in the page source is actually including what its meant to - because i dont think it is..

Re: PHP include function doesn't work in HTML file

Posted: Sun Apr 11, 2010 7:13 pm
by Robert07
From what you've told me so far, it sounds like the code is being "included" but not executed. You can compare the code in the page source with the php file included to be sure, but when php code is executed you will not see the code in the page source.

Re: PHP include function doesn't work in HTML file

Posted: Mon Apr 12, 2010 3:20 am
by loweauto
Robert07 wrote:From what you've told me so far, it sounds like the code is being "included" but not executed. You can compare the code in the page source with the php file included to be sure, but when php code is executed you will not see the code in the page source.

well, the short code that's meant to include the longer code located in contact-script.php is, in fact, being shown in the source code, but it's not performing its function - including the code I need..

right?

any ideas as to why?

Re: PHP include function doesn't work in HTML file

Posted: Mon Apr 12, 2010 11:13 am
by Robert07
Oh, if just the one line of code that includes the file appears in the page source then your server is not treating the html like php as you had planned. So you can either play with htaccess some more or just change the file extension to php. I've never tried to make html files be treated like php.

Re: PHP include function doesn't work in HTML file

Posted: Mon Apr 12, 2010 11:54 am
by roders
Follow this link we are dealing with the same problem as you.
viewtopic.php?f=1&t=115218

Re: PHP include function doesn't work in HTML file

Posted: Mon Apr 12, 2010 12:29 pm
by loweauto
Robert07 wrote:Oh, if just the one line of code that includes the file appears in the page source then your server is not treating the html like php as you had planned. So you can either play with htaccess some more or just change the file extension to php. I've never tried to make html files be treated like php.
actually :P it didnt make a difference when i renamed every file in my site to .php

what would u suggest doing in htaccess?

Re: PHP include function doesn't work in HTML file

Posted: Mon Apr 12, 2010 12:38 pm
by Robert07
If a php file won't execute php code on your server, it sounds like a config issue that you might want to ask your webhost about - or delete the .htaccess file and see if that helps. I don't have any other ideas for you at this point.

Re: PHP include function doesn't work in HTML file

Posted: Mon Apr 12, 2010 3:57 pm
by loweauto
Robert07 wrote:If a php file won't execute php code on your server, it sounds like a config issue that you might want to ask your webhost about - or delete the .htaccess file and see if that helps. I don't have any other ideas for you at this point.
hmm, ill try it again.. (coz i deleted all the duplicates)

if this turns out to be a webhost problem - im not gonna be happy :P