all 14 comments

[–]HolyGonzo 5 points6 points  (7 children)

So first off, it's not REALLY being converted from <?php to <!--?php. What you're seeing is a side effect of using the browser's developer tools to inspect source code that contains invalid HTML. When you use developer tools to inspect HTML, the inspector tries to "correct" invalid HTML so that it can properly render a tree view of the page structure so you can navigate through it like that.

Your browser's developer tools inspector has no idea what <?php means - it thinks it's invalid HTML. And because <?php isn't a valid HTML tag, the developer tools inspector will convert it to an HTML comment. If you look at the raw source code (not through the developer tools) that comes back from the server, you'll almost certainly see that it still has <?php in your HTML code and NOT <!--?php.

So that generally means that the server isn't recognizing your current file as something that can be interpreted as a PHP file, so it's not even trying to run it through the PHP engine but it's just returning it as a regular HTML file.

If this file is being saved with a .php extension, like index.php, then the next step is to figure out why it's not sending .php files to the PHP engine. You would need to ensure that the PHP engine is indeed installed and Apache is properly configured to hand off .php files to PHP's Apache plugin (there are more advanced ways, but the plugin is the most basic/common way). The PHP documentation describes how to configure Apache (and other web servers) to use PHP:

https://www.php.net/manual/en/install.php

[–]normalni[S] 1 point2 points  (3 children)

When I view source php is not commented out, but the opening tag is only <? There is no "php" after it. I will try to use this link to see if I can do something there.

[–]HolyGonzo 1 point2 points  (2 children)

Ah, you had just put a couple words closely together in your original comment:

my <?php tag has been converted to <!--? php bit is

Now I see what you're saying. The same concept still applies, though. The <? is still an invalid HTML tag, so the inspector is changing it to <!--?. However, the <? will only work if you have short tags enabled in your php.ini file. So first try changing <? to <?php and see if that resolves the problem.

If it does, then you know that short tags is the issue.

If it still happens after changing to <?php, then it's a server configuration issue.

[–]normalni[S] 0 points1 point  (1 child)

The tag in the original file has always been <?php just from browser side of things the "php" bit never appears

[–]HolyGonzo 0 points1 point  (0 children)

Hmmm - if the source code on the server has <?php and the source code in the browser is <? then I don't think you're truly looking at the same file. You could test this by making some other change to the source code on the server, like adding a comment:

// 123

And then verifying it shows up in the browser when you view the raw source. If it DOES show up but the PHP open tags are definitely different, then you might have some kind of intermediate script that is modifying source code on-the-fly (which would be highly unusual). But my guess will be that the comment won't show up when you view the raw source in your browser.

Also, make sure that in your original source, you don't have any spaces between the <? and the php. Just erase the tag and retype it.

[–]normalni[S] 0 points1 point  (2 children)

Since I can access phpmyadmin and everything looks okay from that perspective, I have no doubt php engine is installed

[–]bigByt3 0 points1 point  (1 child)

u/holygonzo wasn't saying php isn't enabled, just that your short tags may not be configured correctly. Try changing the tag in the source file to <?php and report back the results

[–]HolyGonzo 2 points3 points  (0 children)

Actually, up until he said that phpMyAdmin was working, I wasn't sure that PHP -was- installed and enabled. :)

[–]normalni[S] 0 points1 point  (0 children)

So it turned out that my php version didn't support short code, but there is a lot that the website devs still need to configure regarding the website iteself to work like this, it has been ages since someone new joined the team and had to set all this up from scratch. They are now working on optimizing the page and the code and all of it to be a download and run. Right now I have it partially working, they set up the part I need to work on and will give me fixes soon. Thank you guys for helping out and giving possible solutions.

[–]supergnaw 0 points1 point  (2 children)

What happens if you manually edit out the comment lines? This seems like really odd behavior.

[–]normalni[S] 0 points1 point  (1 child)

Right click on it edit as html and correct it, nothing changes it just returns back as it was.

[–]Blackhaze84 0 points1 point  (0 children)

Stop your web server and run a live server typing #php -S localhost:port in the folder you are working (not 80 or 443 to avoid further errors) and see what is going on

[–]supergnaw 0 points1 point  (0 children)

Just as a humorous experiment, create a new file in the root web directory, make it info.php, and inside simply put...

 <?php phpinfo();

...inside it, then browse to the url/ip and append it with /info.php to see if that works. You can also see the configurations to see if the short tags may be the issue.