How to force Intellij IDEA resolve HTML file as PHP file - php

I've PHP project, so till now I've been using Intellij IDEA for both Java and PHP without any problem. But now, I've an old PHP project, the project uses HTML files as a PHP files. I mean files with HTML extensions contain PHP code.
However IDEA doesn't recognize them as a PHP file, but when I change extension to PHP it shows everything is fine.
So how can I force IDEA to accept HTML files as PHP files?
Is there any workaround ?

Go to File > Settings > File Types (under IDE Settings).
Under Recognized File Types, find PHP files (PHP) (assuming you're using the PHPStorm plugin as I am, if not find where your *.php file extension is registered). If you click on this, then look at Registered Patterns, you will see all file patterns that will be recognized as PHP files. You can click the green + on the right-hand side of the patterns pane, and it will ask for a file-name pattern to recognize as a PHP file. Enter *.html (or something more specific if your HTML files all follow a similar naming pattern). When you hit OK, it will likely say that *.html is already registered with HTML Files. Go ahead and reassign it, then hit OK on the Settings window. Your *.html files will now be recognized as PHP files instead of just HTML files.
I just tested this out in 12.0.4 and it works as I described above.
Do note, however, that this seems to be an IDE-wide setting, and isn't project specific. This unfortunately means that you will have to re-register *.html with HTML Files when opening your other, newer project with the correct file extensions. This is why I suggested a more specific pattern than *.html if your files allow for it, or if you can change the filenames to allow for that.
The most up-to-date way of doing this in IntelliJ can be found here.

Related

Can I run a PHP code within an HTML file in Windows Server 2019?

I have been trying to understand a way to run PHP within .html in my server 2019. If there is a way to do so? can someone give me some guidance on it?
There was a post on this already How to run php code in html file on windows server?, but it does not seem to be much help.
Thank you for the help!
You cannot execute PHP code in html, you can do that only in .php file with the help of a web server.
You can have an ajax call that will interact with a url (which can be a PHP file resource) and that can return some processed result.
.php file can have html and it will work all fine but you need a web server to run the .php files. You can install wamp/xampp on your windows server and use that to do some processing using your .php file.
I'm not 100% sure why you would do this, .htm and .php files are both common on the internet. You either have to provide a full link containing the file type or perform some sort of rewrite to remove the extension for end user simplicity and this process would be fairly similar whether its .htm or .php youre dealing with.
To answer the question though, i havn't personally done this, but the link you provided implies it should be possible. What they're talking about is adjusting the "Handler Mappings" in IIS. This can be done at two levels, either at Webserver level or Website level. If you open Internet Information Services Manager (assumes you root access to the windows server and not just access to upload a website, if you don't the server admin will need to do this!) you will get a tree down the left side called "Connections". Under Connections either:
Click the PC Name (a server with a globe icon) for server level
Or
Click the website (just a globe under the sites folder for site Website level)
Then you need to find the Handler Mappings on the main window under IIS > Handler Mappings.
they are then suggesting creating a mapping for .htm and .html that follows the same rules as the .php mappings. I would read up on this page and what it does though.
https://learn.microsoft.com/en-us/iis/configuration/system.webserver/handlers/
A couple of things to note:
You may have to install PHP yourself using the Web Platform Installer as i recall it's not there by default on all (if any) versions of IIS. Until you do this you may not see the PHP handler mappings mentioned in the above section.
you will likely need a mapping for .htm and .html separately.
.htaccess files dont work in IIS, you usually have to find a web.config equivalent, i suspect you wont find one for this though due to how IIS works.
If you dont own the server or all of the sites on it, you may wantr to do this at website level first to make sure it doesn't break any of the other sites.

Using Siteimprove Accessability Checker after converting PHP file to HTML does not work

I have some PHP files, my IT department wants to perform accessibility checks on these files, but they said that these files need to be converted to HTML first before they run the checker on them.
Now, I loaded the pages in browser and save them as HTML, but what happens is that the accessibility checker extension which is installed on Chrome (Siteimprove Accessability Checker), does not work anymore. It only works on the PHP files that I see in my browser.
Has anyone had a similar experience? Is there any way to fix it?

HTML file dosent work when it is saved as php and using any php code

I designed my web page using ms office frontpage 2003 as I am little bit familiar with that.Later I saved that using php extension as I want to use more php code in there.But soon after i include any php code it only shows the HTML code in the browser.
Your kind consideration given with this regard is highly appreciated.
You seem to be confused about how PHP and HTML work.
Feel free to use whatever text editor you wish, but PHP code will not show up in the browser. This is the intended behavior. PHP is executed server side, and therefore it is completely invisible to the eyes of the clients (browsers.) If you're not using a server with PHP installed, then your PHP code wont execute, obviously, but under no circumstances should you see PHP code in your browser.
Use an editor like Notpad++ (notepad-plus-plus.org), Editpad Pro (www.editpadpro.com) sublime text (www.sublimetext.com) etc. to edit your html files. Go ahead open your .html or .php files in these editors and make appropriate changes.
UPDATE: PHP scripts run on web server. You cannot just open .php files in browser like .html files. For PHP scripts to execute you need to have a web server. Install XAMPP in your system. https://www.apachefriends.org

Website security - Does php or webserver strip details before returning html?

I am replacing an existing very old site written in another lang with a newly-coded php site and I need to double-check a couple of things with respect to security. Website will be running on Windows 2008 R2 using IIS 7.5 and running php 5.3.8.
I am storing db login creds in a file outside of web root. But in my php code I have to include those files and I am using an absolute path. Will php and/or IIS strip out the file path. (I imagine the answer is yes since competing technologies would do likewise, but need to be sure on this and couldn't find the answer.)
On a related point, what is the best place to keep .js files? Is it better security-wise to keep them outside of web root?
Sorry for the basic questions, but am new to php (long time programmer in other langs).
well, php is different from ASP, so my suggestion is to make a subdomain for js/css, you even can name it CDN... but, it still better than from the root.
I ran a bunch of tests where I looked at the source of what is returned by php and the webserver. If you use the php command "require c:\abc\file.php" neither piece of information is returned with the html.
However, the path to a .js file IS displayed. This is because it sits inside the html, not php, so that path is NOT stripped out by php or the webserver.
So from this I think I can safely say:
1. The path to the creds will not be displayed in the html source returned to the browser or curl call or whatever.
2. js and css paths are shown publicly so it is worth considering whether these need to be secured (e.g., separate subdomain or similar).

Force Content-Type on files with no Extension in EclipsePDT?

I use Eclipse-PDT to work on my PHP projects and find it inconvenient when Eclipse does not recognize my php files that have no extension. Our project contains many cli/bash-style php scripts that have no file-extension (for whatever reason). This results in no code-completion, highlighting, etc for these particular files. It treats them as plain-text.
Is there a way I can mark these particular files as PHP to use the PDT features?
If I remember correctly, you might be able to do something like this :
right-click on the file in the Navigator panel -- or the equivalent you are using
choose Open with > Other...
In the dialog box that pops-up, you should be able to choose the PHP Editor
Next time you'll double-click on that file to open it, it should automatically bge opened using the editor you selected earlier.
But you'll have to do that once for each one of your files, so Eclipse PDT does know for which files which editor it should use...
A workaround suggested by Swooper (in his case for perl) here suggests to create links to the files with extensions and edit the files in Eclipse through those links.
Not ideal and maybe hard if you have a lot of extensionless files, but it will work.

Categories