I'm using PhpStorm 2016 with php language level 5.6 and the interpeter is PHP 5(5.6.24) and xampp version 3.2.2 .
I'm trying to add some php code in html page,
I created a file .htaccess in the same folder where my html file located, and put AddType application/x-httpd-php5 .html .htm inside it, added <?php echo "example" ?> but it doesn't show up.
I even tried <FilesMatch "\.html$">
ForceType application/x-httpd-php
</FilesMatch>, AddHandler application/x-httpd-php5 .html .htm and AddType application/x-httpd-php .html .htm but nothing work, don't know what eles to do.
Hope you can help me with any idea.
Thank you.
You may need to edit the Apache config file, and check if AllowOverride is set to none. If AllowOverride is set to None, .htaccess files are completely ignored.
See httpd.apache.org/docs/2.4/mod/core.html#allowoverride
To allow only the ForceType directive it would be
AllowOverride FileInfo
or if you want all entries in your .htaccess to be honored, then
AllowOverride All
In order to get xampp to interpret the file as PHP, you will need to set the Apache Server web-root to the base of your project (where the html files are) and access the webserver via the server (HTTP in a web-browser).
It sounds like you're trying to access the file directly with the browser (skipping the PHP processor).
Related
My apache runs php files with or without .php extension, How can I disable this and force apache to run php files only with .php extension. I don't want to use .htaccess, this might be an apache config. does anyone know how to disable this option?
Thanks for the answer but using Addtype as you mentioned did not ever work for me, all by itself, even in PHP 5..
Here's what I've tried that DOESN'T work with this version of PHP:
Options +ExecCGI
AddType application/x-httpd-php .php .nusuffix
AddHandler x-httpd-php5 .php .nusuffix
This worked for PHP 5. Now, does not.
This is for a hosted account, so I must do this via .haccess.
You can check your httpd.conf what extensions are configured, it need need to be following. if there is change in your file you can change it to following and restart the apache
AddType application/x-httpd-php .php
more details : https://wiki.archlinux.org/index.php/Apache_HTTP_Server
please add if anything is missing
What I'm trying to do is get my html/php code to display data from my MySQL in a table.
It connects just find to the database, but I think I'm getting an error at: $resultt=$con->query("SELECT DisplayName, Kills, Deaths, Wins, Lost FROM TTPlayer"); for it always shows that code as text on the webpage when I execute it. Also in the tables it shows each of the row methods and their variable Thanks in advance for any help!
Code:
http://pastebin.com/j1EDux5y
Executed webpage:
http://pasteboard.co/2pzqESnw.png
"It is a .html file, I will check on php5_module – ZachtheBoB 2 mins ago"
.html file extensions will not parse PHP directives.
A .php extension is required to do this, plus making sure a webserver and PHP are installed and properly configured.
If on a local machine, you will need to access it like http://localhost/file.php and not file:///file.php
You can however, instruct Apache to treat .html files as PHP through .htaccess if that is your preference.
AddType application/x-httpd-php .html
If you only plan on including the PHP on one page, it is better to setup this way:
<Files yourpage.html>
AddType application/x-httpd-php .html
</Files>
If you are running PHP as CGI
AddHandler application/x-httpd-php .html
If on GoDaddy
Options +ExecCGI
AddType application/x-httpd-php .php .html
AddHandler x-httpd-php5 .php .html
I'm stuck trying to figure out what directives my htaccess file for a directory needs. To give a little background, I was messing around with AddType and AddHandler to try to get html files to run php in them. I was adding directives like:
AddType application/x-httpd-php .php .html
and
AddType application/x-httpd-php5 .php .html
That didn't work, so I tried adding handlers as well:
AddHandler x-httpd-php .php .html
and
AddHandler application/x-httpd-php .php .html
That still didn't give me what I wanted so I tried many combinations, like:
AddType application/x-httpd-php .php .html
AddHandler php-script .php .html
I even tried combinations with SetHandler
AddType application/x-httpd-php .php .html
AddHandler php-script .php .html
SetHandler application/x-httpd-php .php html
I tried every imaginable combination of AddType and AddHandler found on the web.
!===== This is important ======!
I realized that its not good practice to have php run your html files just so you can run php in the html. I am no longer trying to do that. The only reason I'm posting this part above is to give you an idea on some things I've changed. These changes were made to the htaccess file at a directory above the root.
!==============================!
Now that I'm no longer trying to run my php in html files I cleared the AddType, AddHandler, and SetHandler directives from the htaccess file. But now I get an internal server error when trying to run php files.
So I tried putting some stuff back. If I had a handle, the browser now downloads the php instead of running it.
I should note that any php running below the directory I changed works fine. But everything in that directory or subdirectory of that directory has this same problem with php files.
I have tried deleting the htaccess file in that directory, but that does not work, I get an internal error.
If I turn Override off, I get an internal error.
Something I changed is persisting in that directory and I'm wondering how to either
a. turn it off
b. add the correct handler to that htaccess file so that php files are run again (like they are on the rest of the server)
I did have the exact same issue so I deleted all the content of .htaccess and started trying only with handlers until I figured it out. My local .htaccess copy had the following SetHandler:
AddHandler x-httpd-php5-3 .php
In my case it worked after changing it to:
AddHandler application/x-httpd-php5 .php
It seems the whole trick is only the handler, I tried this solution in 2 different servers with different configurations and in both cases just changing AddHandler worked. If this doesn't work for you try a different handler for php.
Hope it helps.
Just realized I left this up unanswered after I solved the problem. If someone has a similar problem and is reading this : Check the permissions on all associated folders. I can't remember the specifics but one of the directories involved (I believe it was the htaccess directory) had permissions that persisted after changing some things and then changing them back.
I wanted to change the .php extension to .foo, to hide it for visitors.
My webserver has cPanel installed, so I logged in and clicked on "MIME Types", and entered the following:
MIME Type: application/x-httpd-php
Extension: foo
The problem is that it's not being parsed as PHP, but instead is downloaded (when you click the link, a file containing all the code of that file is being downloaded)
How would I solve this?
Add in httpd.conf or vhost.conf
<IfModule mime_module>
AddType application/x-httpd-php .foo
</IfModule>
But best way to solve you problem is in using mod_rewrite
If you have the necessary AllowOverride permissions to use .htaccess, try
AddHandler application/x-httpd-php5 .php .foo
For some reason our CentOS server needs x-httpd-php5, where as our WAMP internal server just uses x-httpd-php like you have (and -php5 will not work)
I have a CPanel based website and we used the above rule to set .html to be parsed as php, didn't even bother with the CPanel Mime settings... but there are other ways to determine if a server is running PHP so you're not really hiding that you use PHP from anyone who knows what they are doing
I have many years experience of working with Apache/PHP/MySQL directly and have only just started using WAMP.
I installed WAMP last week and had my first 4 PHP/MySQL websites up and running immediately. How much easier is this I began to think! That is until I added a fifth site and cannot get php to parse any php file below the websites root directory.
I have a test.php file containing just the word 'hello', ho HTML tags and no PHP directives.
If I place this into /wamp/www/ob/test.php it works, if I place it into /wamp/www/ob/html/test.php the browser comes up with 'You have chosen to open test.php, what should Firefox do with this file? Basically php failed to parse it.
My other sites are working fine with identical setup and this site plus three others were downloaded using Filezilla.
Can anybody help please before I uninstall WAMP and go back to installing Apache/MySQL/PHP manually.
Either the php handler is not turned on for that directory, or the content-type of the returned data is set wrong.
My WampDeveloper Pro setup has this...
<Directory "C:/WampDeveloper/Websites/*/webroot">
AddType text/html .php .php4 .php5 .phps
AddHandler application/x-httpd-php .php .php4 .php5
AddHandler application/x-httpd-php-source .phps
</Directory>
This turns on PHP for all website folders.
Has a DefaultType text/html in httpd.conf for fallback.
Also check any .htaccess files, they might be setting content-type to something other than 'text/html'.
The pages on the Internet that explain how to make Apache parse the PHP that you add to a file with the extension HTML suggest this:
AddType application/x-httpd-php .html .php .htm
AddHandler application/x-httpd-php .html .php .htm
If your Apache server is configured for php5 but not php, then the result, I believe, is the refusal described. I changed what I added to .htaccess to this (notice the digit 5):
AddType application/x-httpd-php5 .html .php .htm
AddHandler application/x-httpd-php5 .html .php .htm
That fixed the problem for me.