Jump to content

PHP Parse error: syntax error, unexpected '<'


thesunlover
 Share

Recommended Posts

58 minutes ago, mac_gyver said:

to check what value php is using for the setting, create a .php script with a phpinfo(); statement in it and see what the  line in the output shows for the short_open_tag setting.

This troubleshooting method is somewhat hard for me unfortunately 😞. I am a Linux system admin and the only language (if it can be called a language) is shell scripting. 

Link to comment
Share on other sites

1 hour ago, ginerjm said:

If you make it a habit to use the long open tag this won't be a problem down the road.  

And - if you don't keep switching php modes you won't have to worried about php open tags except at the beginning of your script.

Here is the last post of code you submitted.  See if it makes sense to you how I converted your coding.  Don't know what that addquote thing is but I assumed it was a Php function name.

<?php
if(!defined('IN_DISCUZ')) 
	exit('Access Denied'); 
$code=<<<heredocs
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset="$CHARSET" />
<meta http-equiv="MSThemeCompatible" content="Yes" />
<meta name="description" content="" />
<meta name="keywords" content="" />
<meta name="MSSmartTagsPreventParsing" content="TRUE" />
heredocs;
echo $code;
include template('css');
$code=<<<heredocs
<script type="text/javascript" src="include/common.js">
</script>
<link href='include/mh_css_6.css' type='text/css' rel='stylesheet'>
heredocs;
echo $code;
addquote('$url_redirect');
echo "
<title>";
addquote('$bbname');
addquote('$navtitle');
echo "
</title>
</head>
<body>";

 

I will try it when the web is back online from restoration. Thank you!

Link to comment
Share on other sites

3 minutes ago, thesunlover said:

This troubleshooting method is somewhat hard for me unfortunately 😞. I am a Linux system admin and the only language (if it can be called a language) is shell scripting. 

I don't know how much simpler I can make it for you.

  • ssh into your server
  • cd to the webroot of the site, based on the webserver (apache?) configuration you are running
  • vim phpinf.php
  • Add the code I provided and save
  • Check the owner and permissions of the file, and make sure they match whatever the other scripts in the directory have
  • navigate to https://domain.xxx/phpinf.php
Link to comment
Share on other sites

1 minute ago, thesunlover said:

I will try it when the web is back online from restoration. Thank you!

Please don't.  This is not a problem you can fix by editting source code.  You are running a forum that has templates it compiles and runs.  Changing the source code of the forum or these templates, other than via one of their official patch/upgrade packages isn't going to work.  There is nothing wrong with the code as it was before, and people were confused into thinking that changing it was going to fix errors, because they did not understand that these were templates that get parsed and compiled into a finalized PHP source.  

In short, if you changed any files, hopefully you can change them back to what they were originally.  It is likely you do need short open tags to be on, but that is not the primary problem.  The primary problem is that you are running a version of Discuz! that is incompatible with php7 and needs to be patched.  As this forum is not well known in the english speaking world, it's doubtful that anyone here can be much help to you, but I did find a page that appears to link to some patches and upgrade instructions.

Link to comment
Share on other sites

52 minutes ago, gizmola said:

I don't know how much simpler I can make it for you.

  • ssh into your server
  • cd to the webroot of the site, based on the webserver (apache?) configuration you are running
  • vim phpinf.php
  • Add the code I provided and save
  • Check the owner and permissions of the file, and make sure they match whatever the other scripts in the directory have
  • navigate to https://domain.xxx/phpinf.php

Hi gizmola,
Thank you much for the info. I've located the php.ini file by using your way. Here is the result:

[~/public_html]# grep short_open_tag /opt/cpanel/ea-php80/root/etc/php.ini
; short_open_tag
short_open_tag = On

short_open_tag is on.


 

Link to comment
Share on other sites

More info: The web was reviewed and revised by a PHP/SQL programmer in order to be comparable with PHP 7x two years ago. It has been working fine until PHP 8 is applied recently by the host. Now it seems not working with php 7 for unknown reasons.

Link to comment
Share on other sites

13 minutes ago, thesunlover said:

More info: The web was reviewed and revised by a PHP/SQL programmer in order to be comparable with PHP 7x two years ago. It has been working fine until PHP 8 is applied recently by the host. Now it seems not working with php 7 for unknown reasons.

So let's review:

  • Site was running PHP 7, and was functional
  • Site is now running PHP8 and is broken
  • 2 Years ago, a programmer did *something* with the forum, but you don't know what that something was...
    •    An educated guess would be that they upgraded the version of Discuz to the version that runs under PHP7.

Here's something helpful for you:

https://www.discuz.net/daily/

This is the page of Discuz! Daily builds.  Note that the current version of the forum is 3.4.  So that is the newest current version.

Here is a thread talking about how Discuz 3.4 does not work with PHP8, and there are people stating due to architecture and plugins, that there is no way it's going to be updated to work with php8.

https://www.discuz.net/thread-3852727-1-1.html

Based on what I can see, your only viable option is a downgrade of PHP to version 7.4.  It will be supported until November, and at that point it will be End of life, so you are not yet in a situation where PHP 7.4 should not be used.  Regardless of PHP 7.x's status you are beholden to the support or lack thereof, for Discuz!

In conclusion: you need to downgrade the server to PHP 7.4.  Don't know what Distro you are using, or what level of control you have over it, but that is what I'd be looking to accomplish at this point.  Of course this all makes way more sense now that we've established that:

  • System worked fine with php7.x
  • Broke after upgrade to 8.x

 

 

 

Link to comment
Share on other sites

5 hours ago, thesunlover said:

Thank you much for the info. I've located the php.ini file by using your way.

the complete instructions you were given included - 

Quote

Then use the browser search to find the short_open_tag setting and verify that it is in fact set to On.

doing this will tell you, and us, what the actual run-time value is, which can be different from the php.ini setting.

5 hours ago, thesunlover said:

Now it seems not working with php 7

what is the current version you are trying this on? (guessing 8.0 based on the last php.ini path).

if/when you down-grade to php7, repeat the phpinfo exercise and actually find the short_open_tag line in the resulting output to see what it is.

 

back to the error and the code in question - that the application gets to the point of trying to operate on the php in a template file means that it has values for those php variables and constant, and the application is not completely broken. the php syntax error for eval'ed code usually states that it is from eval'ed code (don't know if this has changed), so this code is probably being required. php syntax errors in requeued code does run the main code up to the point of the require statement.

assuming that nothing has been altered in any code up to this point, in an attempt to 'fix' the current problem, the only way this code could have ever 'worked' is if every instance of the ?'.'> (found in all the short-print tags with a php variable, but not in the short-print tag with a php constant) gets replaced with ?> before it is passed to the php language engine. my guess as to the reason for the ?','> would be that someone passed the template code through a validator and this kluge made it pass validation. the current problem could be simply due to some character matching difference, even the character encoding of quotes inside a string in a file, that is no longer matching the ?','> exactly and is leaving it as is. as a test, i manually changing all the ?'.'> to ?>, there is no php syntax error and the code runs.

where exactly are you seeing that error message? is it output on a web page, and if so, what if anything else is output on the page, including in the 'view source' in the browser? OR are you seeing it in an error log file and the web page is blank? is this a public-facing web site that you can post a link to?

Edited by mac_gyver
Link to comment
Share on other sites

7 hours ago, mac_gyver said:

the complete instructions you were given included - 

doing this will tell you, and us, what the actual run-time value is, which can be different from the php.ini setting.

what is the current version you are trying this on? (guessing 8.0 based on the last php.ini path).

if/when you down-grade to php7, repeat the phpinfo exercise and actually find the short_open_tag line in the resulting output to see what it is.

 

back to the error and the code in question - that the application gets to the point of trying to operate on the php in a template file means that it has values for those php variables and constant, and the application is not completely broken. the php syntax error for eval'ed code usually states that it is from eval'ed code (don't know if this has changed), so this code is probably being required. php syntax errors in requeued code does run the main code up to the point of the require statement.

assuming that nothing has been altered in any code up to this point, in an attempt to 'fix' the current problem, the only way this code could have ever 'worked' is if every instance of the ?'.'> (found in all the short-print tags with a php variable, but not in the short-print tag with a php constant) gets replaced with ?> before it is passed to the php language engine. my guess as to the reason for the ?','> would be that someone passed the template code through a validator and this kluge made it pass validation. the current problem could be simply due to some character matching difference, even the character encoding of quotes inside a string in a file, that is no longer matching the ?','> exactly and is leaving it as is. as a test, i manually changing all the ?'.'> to ?>, there is no php syntax error and the code runs.

where exactly are you seeing that error message? is it output on a web page, and if so, what if anything else is output on the page, including in the 'view source' in the browser? OR are you seeing it in an error log file and the web page is blank? is this a public-facing web site that you can post a link to?

 

I will do it - replace all  ?'.'> with ?>

----------------------------------------------------------------

The web is down with error 500. Errors are reported in the sitelock scanning log. Here are all of them:

[22-Apr-2022 21:58:09 UTC] PHP Parse error: syntax error, unexpected '<' in /home/public_html/forumdata/templates/1_articlelist.tpl.php on line 19
[22-Apr-2022 21:58:26 UTC] PHP Parse error: syntax error, unexpected '<' in /home/public_html/forumdata/templates/1_articlelist.tpl.php on line 19
[22-Apr-2022 21:58:28 UTC] PHP Parse error: syntax error, unexpected '?' in /home/public_html/forumdata/templates/1_viewthread.tpl.php on line 9
[22-Apr-2022 21:59:26 UTC] PHP Parse error: syntax error, unexpected '<' in /home/public_html/forumdata/templates/1_viewthread_printable.tpl.php on line 16
[22-Apr-2022 22:00:12 UTC] PHP Parse error: syntax error, unexpected '?' in /home/public_html/forumdata/templates/1_viewthread.tpl.php on line 9
[22-Apr-2022 22:00:54 UTC] PHP Parse error: syntax error, unexpected '?' in /home/public_html/forumdata/templates/1_viewthread.tpl.php on line 9
[22-Apr-2022 22:00:54 UTC] PHP Parse error: syntax error, unexpected '<' in /home/public_html/forumdata/templates/1_articlelist.tpl.php on line 19
[22-Apr-2022 22:01:11 UTC] PHP Parse error: syntax error, unexpected '<' in /home/public_html/forumdata/templates/1_showmessage.tpl.php on line 7
[22-Apr-2022 22:01:33 UTC] PHP Parse error: syntax error, unexpected '?' in /home/public_html/forumdata/templates/1_viewthread.tpl.php on line 9
[22-Apr-2022 22:02:53 UTC] PHP Parse error: syntax error, unexpected '<' in /home/public_html/forumdata/templates/1_blog.tpl.php on line 19
[22-Apr-2022 22:02:59 UTC] PHP Parse error: syntax error, unexpected '<' in /home/public_html/forumdata/templates/1_showmessage.tpl.php on line 7
[22-Apr-2022 22:03:15 UTC] PHP Parse error: syntax error, unexpected '<' in /home/public_html/forumdata/templates/1_articlelist.tpl.php on line 19
[22-Apr-2022 22:03:53 UTC] PHP Parse error: syntax error, unexpected '<' in /home/public_html/forumdata/templates/1_showmessage.tpl.php on line 7

Error 

 

 

 

 

Link to comment
Share on other sites

3 hours ago, foxclone said:

Is it possible that the host has removed PHP 7.4 and installed PHP 8 in anticipation of the upcoming EOL for 7.4? I'd confirm that PHP 7.4 is still available on your host.

Yes. php 7x is still available. I will try it again after the web is back online from restoration.

Thanks!
 

Link to comment
Share on other sites

Those error messages are telling you that there is an error on line 19.  They are NOT telling you that "the web is down...".  

Show us line 19.

PS - many voices here will tell you that you never need to use a PHP closing tag (?>) .   So if you follow my previous example (above) if you never try to output html 'outside' of php mode, you'll never need to use a closing tag.

Not to brag but I write very long scripts sometimes a 1000 lines and I never leave PHP mode. 

Link to comment
Share on other sites

Looking at your old posts here I found this "line 19".

<title>
addquote('<?=$bbname?' . '>')
addquote('<?=$navtitle?' . '>')
</title>

I broke it down to make it easier to discuss.  Can you see now that you have mis-used the php closing tags here?

And just what exactly is "addquote()"  Is it a php function?  If it is you are definitely not using it correctly.  The code all around line 19 is HTML code and right in the middle of it you are introducing a php function call.  If you really wanted to write this code here is one way to do it properly:

echo "<title>" . addquote("$bbname") . addquote("$navtitle") . "</title>";

Note that my using the echo command here implies that I am IN php mode.  Never left.  Never re-entered. 

Note that I also use some space chars to help separate the pieces of that long statement.  A good practice to make one's code readable to you down the road and to others who may have to work with it perhaps.  And if you are not aware of it, using double quotes (") to wrap php vars is a requirement if you want them to be properly interpreted.  Single quotes around the 2 vars in the above would simple give you literally $bbname and $navtitle in your html code and that is not what you want.

Link to comment
Share on other sites

2 hours ago, thesunlover said:

I will do it - replace all  ?'.'> with ?>

no one stated that was a solution. just as a test it caused one small part of the problem to no longer produce a php syntax error.

if the ?'.'> exists throughout the templates, there's probably a reason for it, regardless of how bad of a reason it is. unless you actually find what's causing the problem and correct it, you will end up wasting a lot of time for nothing.

given that you haven't read, translating as necessary into your native language, and followed all the instructions given or answered all the questions asked, i don't think we can help you.

Link to comment
Share on other sites

7 hours ago, ginerjm said:

Looking at your old posts here I found this "line 19".

<title>
addquote('<?=$bbname?' . '>')
addquote('<?=$navtitle?' . '>')
</title>

I broke it down to make it easier to discuss.  Can you see now that you have mis-used the php closing tags here?

And just what exactly is "addquote()"  Is it a php function?  If it is you are definitely not using it correctly.  The code all around line 19 is HTML code and right in the middle of it you are introducing a php function call.  If you really wanted to write this code here is one way to do it properly:

echo "<title>" . addquote("$bbname") . addquote("$navtitle") . "</title>";

Note that my using the echo command here implies that I am IN php mode.  Never left.  Never re-entered. 

Note that I also use some space chars to help separate the pieces of that long statement.  A good practice to make one's code readable to you down the road and to others who may have to work with it perhaps.  And if you are not aware of it, using double quotes (") to wrap php vars is a requirement if you want them to be properly interpreted.  Single quotes around the 2 vars in the above would simple give you literally $bbname and $navtitle in your html code and that is not what you want.

 

@ginerjm:  Did you read any of the posts I made, specifically the one that pointed out these are templates that get compiled?  

How exactly can someone make use of the addquote() function in a section of html markup?  

The solution to the problems here are not to rewrite templates, as they were working fine before the server was upgraded to php8.

 

Link to comment
Share on other sites

I have already asked what those addquote lines were but saw no answer.  As for templates, I don't know how that could be part of this nor how they could be buried in the HTML as the OP seems to be doing.

I am simply looking at some horrendous html/php mashup and trying to make it clearer to the OP.  Apparently I am wrong.  I'll step aside.

Link to comment
Share on other sites

The first tip off in this was that somewhere in a prior post, the OP posted the name of the script that was  somename.tpl.php.

Next you can see from the snippets that there is pure HTML blocks, with a snippet of PHP code inside these mysterious addquote() functions, so you are of course right to have brought that up.  Obviously these scripts can't possibly work as is, because the way the addquotes are used within html tags, something else had to be going on.  Then we see that inside the addquote calls are small string operations that appear to be outputting various php blocks.

So based on this evidence it seems likely that what is happening is that these *.tpl.php scripts are being run through a compiler which compiles them into the final php scripts that drop in and out of php frequently.  

Since then, of course we were able to identify that this is the forum software Discuz! which is popular in China.  I found and posted links to a few threads on the official forum that state that the most current version of Discuz! is incompatible with PHP 8, for whatever reasons.  

Link to comment
Share on other sites

Hi Guys,

Thank you very much again for your help. You are just great!

As a system admin, this issue is too hard for me. If there is no simple solution, I will have to hire a PHP programmer to do the troubleshooting.

Regards,
 

Link to comment
Share on other sites

5 minutes ago, thesunlover said:

Hi Guys,

Thank you very much again for your help. You are just great!

As a system admin, this issue is too hard for me. If there is no simple solution, I will have to hire a PHP programmer to do the troubleshooting.

Regards,
 

Probably a good decision.  I never cease to be suprised by all the different PHP based software in use around the world, but I do think that it may be a challenge to find someone with experience in your forum that isn't a Chinese language speaker, as again, it seems primarily to be used in China.   I had never heard of it before, and I've been involved with PHP development and applications for 20 years.

The Discuz! forum is now owned by Tencent, and part of a suite of products offered under the "Comsenz" subsidiary.  I found a few things for you that might be of benefit to whomever you work with:

  • Main Comsenz site
    • Here is where they advertise and sell their licensed versions
  • Comsenz Github page
    • Has a lot of Discuz! open source releases, but I'm not sure what parts comprise the forum.  The newest release I found was December of 2020.

I don't know what community this is for, but the best decision for you, if this is not a Chinese language site/community might be to look for a way to migrate to a better maintained platform.  I would need to know more about your current site and community to offer better advice, but I would have serious concerns about going forward with something Discuz! based, again dependent on the answer to those questions.  

With that said, if you want to post for some help we do have some sub-forums that can be used for that here:  https://forums.phpfreaks.com/forum/79-freelance-contracts-employment-etc/

 

 

Link to comment
Share on other sites

@thesunlover - There's a freshly released version of your system: Discuz! X3.4 official version [2022-04-06]. You can get it at https://www.discuz.net/. The source code is also available from that site. You can pass that information to whoever you hire, if you go that route.

Link to comment
Share on other sites

1 hour ago, foxclone said:

@thesunlover - There's a freshly released version of your system: Discuz! X3.4 official version [2022-04-06]. You can get it at https://www.discuz.net/. The source code is also available from that site. You can pass that information to whoever you hire, if you go that route.

Thanks for the info. I think Discuz! is not stable in business and technique. I am thinking to transition the forum from Discuz! to WordPress if possible. Now I am trying to find and hire a php professional from upwork.

Link to comment
Share on other sites

5 hours ago, thesunlover said:

Thanks for the info. I think Discuz! is not stable in business and technique. I am thinking to transition the forum from Discuz! to WordPress if possible. Now I am trying to find and hire a php professional from upwork.

Is your server primarily a forum?  Plenty of people use Wordpress, but it is not the best architected, current nor performant platform out there.  It also is a blog, and has no built in forum, commerce, or other features, so for that you have to go with a plugin, and perhaps multiple companies you are keeping up with.  I say this as someone who has installed, modified and supported a number of Wordpress based sites over the years. 

Again, if you could tell us more about the site, and what it is for, I'd have more ideas, but it might be better to go with Invision if you can afford a relatively low cost license and subscription for something that has a large installed user base and many users.  

See https://invisioncommunity.com/ for more information.  They have a complete suite of products for communities, which can include commerce and subscriptions, and site building.  This forum has used a number of different forum packages over the years and eventually settled on IPB, which we used with very little customization.

Another long time commercial competitor is vBulletin, which has hosted a lot of really large internet communities over the years:  https://www.vbulletin.com/  With that said, most of the original vBulletin developers created a new product, Xenforo that has a newer more modern codebase.  https://xenforo.com/purchase/self-hosted

For completely free/open source, there are other CMS platforms like Drupal or the Drupal 7 Fork, Backdrop CMS.  They would be similar to Wordpress, only with a modern codebase, and are frequently used as an alternative to Wordpress for people who are more in need of a site building platform.

Drupal: https://www.drupal.org/

Backdrop CMS:  https://backdropcms.org/

There's a bunch of software you can Demo here:  https://www.opensourcecms.com/forum-software/

It includes a list of other Forums that have been around for a while.  I have a preference for more current codebases, but then you also take the chance that the projects will stagnate.  I do think that some of the newer forums are better architected, and built upon core components like the Symfony components, that have been used in a lot of projects and have robust Unit tests and a large community of users.  

Along the lines of modern/different is Flarum:  https://flarum.org/

I have been watching this project grow for the last couple of years, and one of the things I really like is the way they've coded around modern components, and the open source/sponsorship model.  I actually created a forum with Flarum a year or so ago, and found it to be really good, but the project was scrapped.  Since that time it's only gotten more mature.  It is a flat thread model, driven by tags for categorization, so it might work better for certain types of communities vs. others.  

Flarum github here:  https://github.com/flarum

Good luck!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.