I have made a subdomain and uploaded php script on that. but php code is shown there included file are also not shown on page.
In description, i have made a sub domain jobs.example.com. All project done in php on locally when is uploaded it to the srever (in the root flder of jobs.example.com). only html css and jquery is running php code is shown there as it is. How may i handle this plese help me.
My guess is: may be you might need to set up your subdomain folder to run php files.
You might need to setup mime type for .php
# Add this line inside the <IfModule mod_mime.c> conditional brace
AddType application/x-httpd-php .php
Referenced from : http://www.php.net/manual/en/install.windows.apache1.php
Related
I've searched all over the internet and can't seem to find a solution to my problem. I want to be able to "call" a php file from an html file and display the string returned:
html_ONLY_file.html
...
<h1>GetHeader.php?type=main</h1>
...
GetHeader.php
if($_GET['type'] == 'main')
print 'Some header to display'; //or echo 'Some...';
exit;
I've done this for images, img src="image.php?file=file.jpg", where image.php does a header(...) and readfile(...) return but I do not know how to do this for simple text. I'm not looking for DOM or anything too involved, if I have to I will. I want to know if there is a simple solution. It's generating the html side that I'm lost on.
In case you want to know, I am doing this because I once used a <#virtual include=...> to call for a php file from my .shtml file. Well, the hosting company decided to change mod_security and now I cannot include any php files (I've already tried everything). Including html files works fine and so I am changing this part of the website around so I don't have to rename files because the site is for a small business that is now ranked highly on Google for its geographical area. If I change the file names, shtml to php, then I believe the Google ranking drops (don't comment on this part unless you are damn sure you are 100% correct).
If you can edit the .htaccess file you can add a line in your .htaccess file that will mean HTML files will be parsed as if they were PHP.
If your server is running PHP as an apache module:
AddType application/x-httpd-php .html .htm
If your server is running PHP as CGI:
AddHandler application/x-httpd-php .html .htm
Source: http://www.besthostratings.com/articles/php-in-html-files.html
Once you've added that your html_ONLY_file.html could look like:
<h1><?php print "some header"; ?></h1>
And it would function just as if it were a .php file.
Alternatively, you could convert all your files to .php and add redirects into the .htaccess file like so:
rewriteRule ^somefile.shtml$ somefile.php [R=301,L]
rewriteRule ^another-file.shtml$ another-file.php [R=301,L]
This effectively says to your server "whenever a user requests somefile.shtml, act as if they requested somefile.php instead". The R=301 is the most important part with regards to Google rankings. This tells Google (and anyone who requests the .shtml file) that it's permanently moved to the new location somefile.php. This transfers all / almost all of the ranking power from the old location to the new location.
Source: http://moz.com/learn/seo/redirection
First of all, I am not trying to run php within a js script, there is a similar question on here that refers to a user trying to run php from inside a js script.
I have added many combinations of
AddType application/x-httpd-php .php .html
AddHandler x-httpd-php .html
to the .htaccess file in a higher level directory containing the .html file I want to run php in. This has not worked. (I am open to trying new combinations)
The is either not read at all or commented out when viewing the source in broswer.
My question is how to get to be run inside of an html file OR is there a better way to include php functionality in an html document without having the code in the same document.
Additionally my host uses cpanel if this helps anything.
I can elaborate on anything I need to, thanks in advance.
You can try to use mod_rewrite for that task:
RewriteEngine On
RewriteRule ^(.*).html index.php [QSA]
I have been trying to execute php code within a document with an .htm or .html extension. I finally got it working using:
AddType application/x-httpd-php .php .html .htm
Now, being able to execute php within .htm documents, only works if I go directly to the .htm page such as: http://www.foobar.com/layout.htm
However, it does not work if I go to the index.php page which uses that layout.htm page...
This is an example of what the index page url looks like: http://www.foobar.com/index.php
What am I doing wrong?
Assuming that you are using something like include in your php file to include the html file, your .htaccess rules will not have any effect on the included file.
The .htaccess rules only get executed on requests that are made to the apache web-server and when you include a local file in php, you are simply requesting a file on the local file system; you are not requesting it through apache.
Edit: Based on the comment below your question, it is also possible that you are using something like readfile to get the contents of the htm file. If that is the case, you need to change that to include so that the php gets executed.
Your .htaccess rule does not apply for included files in php.
Did you check this page: http://php.net/manual/en/function.include.php
When a file is included, parsing drops out of PHP mode and into HTML mode at the beginning of the target file, and resumes again at the end. For this reason, any code inside the target file which should be executed as PHP code must be enclosed within valid PHP start and end tags.
I would really like my index.html to be able to have a PHP script work on it. I read that you can do this through the htaccess file. I only have access to a subdomain website directory, where I can upload my files through FTP.
The directory did not have a htaccess file, so I created one using notepad: .htaccess and added this to the file:
AddType application/x-httpd-php .html
The problem is, instead of loading the index.html page, it downloads it as a file...would I need to add something extra to the htaccess file? :S
You don't need to name the file index.html to have it served by default. You can change the default document using your with an entry in your .htaccess file like this:
DirectoryIndex index.php
Then when you navigate to http://yoursubdomain.example.com you will be served index.php instead of index.html.
If really do want PHP to interpret your .html documents then the entry you had in your question will work when PHP is running as an Apache module. If your host is running PHP as CGI, you want:
AddHandler application/x-httpd-php .html
If it still doesn't work, then this web page has some more suggestions:
http://www.velvetblues.com/web-development-blog/how-to-parse-html-files-as-php/
The directive you have sets the content-type of files with a .html file extension.
If the server has PHP installed and enabled, that content-type will cause it to be run though the PHP engine and then the output from that sent to the client.
If it doesn't have PHP installed, then the file will just be served up to the client with that content-type. Since browsers don't handle PHP scripts themselves, they will then just save the file.
You need to install and enable PHP as well as setting the content-type.
Presumably your hosting is supporting PHP?
If so, then you need to rename your file from index.html to index.php
I'm trying to set up my .htaccess file correctly and I'm having an issue.
The only thing my .htaccess file at the moment is:
AddType application/x-httpd-php .php .html .htm
This is included because my server is not parsing php in my html files.
However when this is included in my .htaccess file, when I open a page in my browser, the user is prompted to save or open the file locally.
I believe the answer to my issues is setting up an action to be done (run with php) however I cannot find out the path to my php files.
Any help is appreciated.
You will need to edit the configuration for enabled modules. On a Debian/Ubuntu type system this will be in /etc/apache2/mods-enabled The file you are looking for is php5.conf
So far all you have done is specify that (dot) htm, html or php files should be served -by default- as application/x-httpd-php, and to my knowledge there is not a single web browser that would attempt to interpret such content -- hence the save-as dialog.
Either you could fix your .htaccess file not to be broken (it is broken behaviour to serve html files as application/x-httpd-php), or you could manually output the correct HTTP headers using the PHP header() function.
Unfortunately, everyone seems to love abusing AddType (and then complain e.g. that MultiViews is broken). See this article, please.
This is not supposed to work in all cases. It depends on the AllowOverride directive of the web server.
You shoud specify the AddType in the serveur config file rather than in the htaccess.