Forum Moderators: coopster

Message Too Old, No Replies

[Newbie] Parsing HTML as PHP on Apache crashes the site

Using .htaccess & addtype

         

waggamama

3:58 pm on Feb 24, 2005 (gmt 0)

10+ Year Member



Complete newbie (i.e. this afternoon!) to php, any help very much appreciated.

I added the following line to the .htaccess file in my root directory:

AddType application/x-httpd-php .php .htm .html

It worked beautifully, but the rest of the site crashed with the following error & obviously I've had to reinstate the previous .htaccess file. I don't know which versions of apache & php are being used here, but I could find out.

Parse error: parse error, unexpected T_STRING in /home/**directories**/calendar.html on line 1

thanks again!

[edited by: jatar_k at 6:48 pm (utc) on Feb. 24, 2005]
[edit reason] removed url [/edit]

gettopreacherman

5:13 pm on Feb 24, 2005 (gmt 0)

10+ Year Member



Without seeing your code, I would think you are missing a ";" on the end of the line...especially if you are seeing errors from line one for the calendar.

waggamama

5:38 pm on Feb 24, 2005 (gmt 0)

10+ Year Member



Many thanks Preacherman. Adding ";" to the end of the line did stop the site crashing, but unfortunately the php isn't parsing anymore. Seems I can't win! Does anyone have any other ideas? The only thing I've got in my .htaccess file is:

AddType application/x-httpd-php .php .htm .html;

thanks again

waggamama

gettopreacherman

5:55 pm on Feb 24, 2005 (gmt 0)

10+ Year Member



Can you post some of the code to the file that you are having issues with? It's tough to solve when we can see it.

waggamama

8:02 pm on Feb 24, 2005 (gmt 0)

10+ Year Member



Sorry, didn't think to do that. All I've got is 4 includes:

<? include("navscript.php")?>

<? include("header.php")?>

<? include("navigation.php")?>

<? include("footer.php")?>

with xhtml between them which has previously validated.

thanks again

gettopreacherman

8:48 pm on Feb 24, 2005 (gmt 0)

10+ Year Member



Try <?php as the opener for your php calls. Sometimes with mixed pages, they don't catch on too quickly. If you start it with <?php then end with?> it usually works better.

waggamama

9:04 pm on Feb 24, 2005 (gmt 0)

10+ Year Member



I changed one of the includes to:

<?php include("header.php")?>

Still didn't work unfortunately. Did I do it right?

gettopreacherman

9:22 pm on Feb 24, 2005 (gmt 0)

10+ Year Member



Yeah, but you are missing the ";" at the end of the includes...lol...missed that the first time. should look like:

<?php include("header.php");?>

waggamama

9:39 pm on Feb 24, 2005 (gmt 0)

10+ Year Member



Rats, got hopeful about that one. Changed it to below & uploaded, but no luck. Wouldn't I get error messages if the Php was wrong? But I get none, which does suggest that it's not parsing at all, I think.

<?php include("header.php");?>

DeadlyDesigns

9:51 pm on Feb 24, 2005 (gmt 0)

10+ Year Member



AddType application/x-httpd-php .php .htm .html;

it is because you are telling apache that .htm and .html is application/x-.....

try

AddType application/x-httpd-php .php;
instead

if that dont work, try no terminator... I dont use .htaccess so idk if your supposed to use them. but i thing that .htm and .html crap messed u up

waggamama

10:05 pm on Feb 24, 2005 (gmt 0)

10+ Year Member



Afraid no. Don't know what no terminator is, but I'm calling it a night anyway. Thanks again for your help with this.

jatar_k

11:44 pm on Feb 24, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Alright there seems to be a fair bit of misdirection in this thread, let's see if we can get things cleared up

as to the line you should use in .htaccess, the line you had originally is right

AddType application/x-httpd-php .php .htm .html

this will cause any files with the extensions .php .htm and .html to be parsed by php. This line is not to be terminated by a semicolon.

full htaccess tutorial
[httpd.apache.org...]

alright so with that cleared up we need to look at your error. i would write the file like so

<?php
include "navscript.php";
include "header.php";
include "navigation.php";
include "footer.php";
?>

make sure there are no blank lines above your <?php tag. You don't need to have the <?php?> for each individual include.
This <?php means turn the php parsing on.
This?> means turn the php parsing off.

so, as long as you still have php code then leave the parser going. See what that change to your .htaccess and this for your file does and then report back when you wake up. ;)

The most common scenario for this error

Parse error: parse error, unexpected T_STRING in /home/**directories**/calendar.html on line 1

is forgetting a $ or forgetting to put // before your comments.

waggamama

10:49 am on Feb 28, 2005 (gmt 0)

10+ Year Member



Hi, I've solved this now, thanks so much for the help. There was an XML call in the first line of every page of the site that wasn't working with the php parsing.

I see what you mean about the php code in my file but what happens if I don't want all the includes to be called together? E.g. I want to call navigation at the top of the file and then footer at the bottom. Should I leave the php parsing on for the entire page or is it more efficient to turn it on and off several times?

jatar_k

6:10 pm on Feb 28, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



well, sticking with our previous example your actual page may look something like this

<?php
include "navscript.php";
include "header.php";
include "navigation.php";
?>

<p>fancy html stuff here

<?php
include "footer.php";
?>

jump in and out of php as much as you like. It depends on what your page is doing, if you need to spit out a big chunk of straight html then drop out of the parser. If you need to build an html table in a loop then just echo your rows, or not.

It really depends on your personal style and what a script is doing.

waggamama

8:41 am on Mar 1, 2005 (gmt 0)

10+ Year Member



Thanks, that's cleared that up for me. Really appreciate the help!