...

View Full Version : -> Mistakenly regarded as php end tag ?>



registereduser4
03-25-2010, 08:52 PM
I composed my php codes through Microsoft Notepad. I use <?php and ?> as start and end tags. They were working well with another free web hosting service. Now I moved to another hosting service and found a problem:

The server mistakenly treat first -> as ?> and end the problem. For example my code is:


<?php
require_once("user.php");
if (0!=strlen(trim($_POST["hiddenUserId"])) && "null"!=$_POST["hiddenUserId"])
{ $u = User::getById($_POST["hiddenUserId"]);
$u->col1stWidth = $_POST["width1st"];
$u->recentNumber = $_POST["numberCol"];
$u->save();
}
?>

It stops at first -> just before col1stWidth. I actually tried other php files, all having same problem.

Fou-Lu
03-25-2010, 08:59 PM
And why do you believe that its treating that as an ?>? Does it show the remaining code as plain text in the output?
Enable you're error reporting or view you're error logs. Chances are you have an issue with regards to a fatal error on accessing an invalid member on a non-object. So you script terminates not because its confused by the end, rather because you have a fatal error. Cause could be due to invalid definitions, failed inlcludes (not in this case since its required and would have died there) and invalid arguments for constructions, or invalid namespace definitions (5.3+).

MattF
03-25-2010, 09:13 PM
Should User not be $User? (Mind's in slow mode today :D).

Fou-Lu
03-25-2010, 09:19 PM
No, User represents a static call to the User class. $u is the resulting variable; I assumed that the User::getbyid method returned a new User instance.


ALSO, just thought of another potential problem here that could be cause and reason. If the remaining (or at least some of it) code shows as plain text in you're browser, open you're source code to see if the previous is embedded as an html tag. If so, you're current configurations are not allowing PHP to be parsed as php, rather they are parsed as .html instead. I also assumed that this file is a .php one since no shebang line is present to indicate otherwise.

registereduser4
03-25-2010, 09:22 PM
I would not think it is a fatal error because it runs well in another web hosting service. And yes, the remaining code as plain text in the output. However, your guess is reasonable because at least my db.php had been changed. If I have connection problem, do you think it would show this kind of error rather than connection error message? Thanks.


And why do you believe that its treating that as an ?>? Does it show the remaining code as plain text in the output?
Enable you're error reporting or view you're error logs. Chances are you have an issue with regards to a fatal error on accessing an invalid member on a non-object. So you script terminates not because its confused by the end, rather because you have a fatal error. Cause could be due to invalid definitions, failed inlcludes (not in this case since its required and would have died there) and invalid arguments for constructions, or invalid namespace definitions (5.3+).

registereduser4
03-25-2010, 09:26 PM
Yes, most likely this is the case. It is .php file.


ALSO, just thought of another potential problem here that could be cause and reason. If the remaining (or at least some of it) code shows as plain text in you're browser, open you're source code to see if the previous is embedded as an html tag. If so, you're current configurations are not allowing PHP to be parsed as php, rather they are parsed as .html instead. I also assumed that this file is a .php one since no shebang line is present to indicate otherwise.

Fou-Lu
03-25-2010, 09:26 PM
Look at my edit in the last post I made. Check that source, does that show as an html tag that contains that code?


Ah great, you saw that last edit.
Confirm PHP is runnable:


// Save as phpinfo.php
<?php
phpinfo();
?>


Does that list all of the configuration information about php, or does that show the text:


<?php
phpinfo();
?>

?

registereduser4
03-25-2010, 09:32 PM
Show me nothing. Complete blank with Done in footnote.


Look at my edit in the last post I made. Check that source, does that show as an html tag that contains that code?


Ah great, you saw that last edit.
Confirm PHP is runnable:


// Save as phpinfo.php
<?php
phpinfo();
?>


Does that list all of the configuration information about php, or does that show the text:


<?php
phpinfo();
?>

?

MattF
03-25-2010, 09:37 PM
No, User represents a static call to the User class. $u is the resulting variable; I assumed that the User::getbyid method returned a new User instance.

I thought I was missing something. I'm having a codeblind mode day. :D

Fou-Lu
03-25-2010, 09:40 PM
If you check you're source code, I'll bet it shows that as an HTML tag.
Problem here, .php is not set up to parse php files. If this is a personal server, you'll need to add:


LoadModule php5_module "/path/to/php5apache2_2.dll" #use php5apache2.dll for apache 2.x, use php5apache.dll for apache1.x
AddType application/x-httpd-php .php

That should do it. If you're hosted, contact you're host and tell them to enable you're php. If you're on a free host, chances are you don't have php available for use.

registereduser4
03-25-2010, 09:49 PM
Thank you so much for such quick to identify the problem.


If you check you're source code, I'll bet it shows that as an HTML tag.
Problem here, .php is not set up to parse php files. If this is a personal server, you'll need to add:


LoadModule php5_module "/path/to/php5apache2_2.dll" #use php5apache2.dll for apache 2.x, use php5apache.dll for apache1.x
AddType application/x-httpd-php .php

That should do it. If you're hosted, contact you're host and tell them to enable you're php. If you're on a free host, chances are you don't have php available for use.

Fou-Lu
03-25-2010, 09:51 PM
Thank you so much for such quick to identify the problem.

Hah, I just noticed I didn't tell you where to add that. It needs to go into httpd.conf, generally located (on windows) at C:\Program Files\apache\conf or in Linux at /etc/httpd/conf



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum