I got a forum in PHP and I got a website in HTML
I need to utilize the website template "to unify the appearance" to output the forum contents
I got stuck when I wanted to include the PHP code into the html file
I used the
<?php echo "here goes my PHP code" ?>
but it does nothing to me :(
so can I get some help to move forward in my development
I have tried and get tired of Posting the code piece here so I decided to post the question and try to figure out the code posting later if needed
thanks anyway
If it "does nothing" then the web server (if there is one) is probably passing the file "as-is" to the browser, and the browser is interpreting it as an unknown tag.
You must:
Access the page through a web server
Be using a web server that supports PHP
Have the web server configured to treat that file as PHP (by default, on most systems, this is done by giving the file a .php file extension)
wanted to include the PHP code into the html
HTML is usually not processed by PHP. Only files (in default configuration) that end with *.php are passed thru PHP interpreter. If these HTML files you are willing to alter are standalone files (and you access them directly like http://domain/file.html), then you can try to enforce PHP there. If your server is Apache and you can tune its settings with .htaccess file (or if you can alter main Apache's configuration) then you can try adding this to your .htaccess
<Files "*.html">
ForceType application/x-httpd-php
</Files>
If you are aiming at HTML templates then basically you are out of luck as these files are not going thru webserver but are read by i.e. your forum and usually processed (not executed etc) inside the code. Slight chances are that forum uses i.e. Smarty templating engine and you can tweak the forum code to enable PHP in Smarty templates.
EDIT
For PhpBB .htaccess won't do the trick, as these HTML files are plain templates. However you can enable PHP in templates in Security Settings. Just set "yes" to "enable PHP in templates". Once you do that you can use PHP code, but while PHP code itself is the same, PHP blocks are marked differently than usual <?php and ?>. Instead of
<?php echo "Test"; ?>
you need to wrtite
<!-- PHP --> echo "test"; <!-- ENDPHP -->
Related
I've installed WIndows 10 version of XAMPP with MySQL (MariaSQL) & PHP version 5.6.28
The SQL is working just fine, i.e., I can log in, create DATABASE, etc.
php -v works fine on the command line ... PHP 5.6.28 (cli)...
phpinfo.php works as expected.
It tells me display_errors is ON
php.ini = display_errors=On
As a php script: mysql_test.php output to the screen is fine.
<?php
echo "Hello World of PHP!";
echo mysql_connect ('localhost', 'joe', 'gonzo9876');
?>
When I embed it in plain vanilla HTML, i.e., http://localhost/mysql_test.html
The php code won't echo/print on the screen
- and -
when I right-click for viewing the source code, the php code is visible
- and -
the Google debugger has converted the php tags to
Your Apache, by default, will only run files with .php extension as PHP. .html will be displayed to browser as is.
You need to either:
Rename your file from mysql_test.html to mysql_test.php; or
Config your Apache to also treat .html files as PHP script
The later one is an unusual practice. I wouldn't recommend it.
Basically no hosting provider will do it. So even if you make it work in your XAMPP setup, it won't work in any normal shared hosting. So if you potentially need to move your code to a shared hosting, please don't do it.
You can't process the PHP code inside html page with .html extension(without parse). It's only for rendering html, if you wanna use embed/mix both php with html, then use .php extension instead as PHP is server-side scripting language. When talking about server-side language, you need a server either local(xampp,wampp,etc..)/production server to host and run your apps.
Reflect to Commenter's comment :
Another workarounds is by telling the Apache to treat .html as .php and with this, you can mix php code with html by using .html, but it's just kinda a HACK for me(personal perspective). Well the choice is yours.
You need to make extension .php if you want to put php code inside html tags. But if you do not want to show .php, please use .htaccess for url rewrite. You can make file as .php but with .htaccess you can show as .html so user will see it as .html.
RewriteEngine On
RewriteRule ^test.php test.html [R=301,L]
or something like this, please search for url rewrite for more detail.
I have a html file and I want to run PHP code to call out an array value within HTML form box but the interpreter doesn't recognize
<input value="<?php echo $_SESSION['user']; ?>"/>
p.s. Not sure if it makes any difference but I am running this on cloud9 with apache (httpd).
Save your HTML file as a PHP file since HTML files cannot execute php code. For example if your file is named index.html you want to re-save it as index.php once you do that your php code should run.
HTML files does not parse PHP. You need to have a file with .php as extension to run PHP.
PS: Its possible to make HTML file run PHP as well but that requires some extra settings in apache config which is never enabled by default. Reason being a security threat. But If you have a dedicated server which allows playing with apache config then you can achieve this..
have a look at this LINK
Ok I figured out that it was actually working all along =/ (i was only looking at the local IDE display within cloud9 but the code was working all along since it actually required back-end processing and the local IDE won't display that).
I'm a newbie to Facebook app development. It almost works when the page liked.php is shown (it's shown when a user liked the site), the PHP code is displayed as text output.
my liked.php code:
deleted for privacy reasons
?>
Here's the output(it's shown as blank text):
I simply don't know why. Even the error_reporting(E_ALL); doesn't show anything. Simply blank text output. I use the newest facebook php sdk.
I guess the problem is not in the code but in the configuration of your server. You need to tell the server to execute the php code instead of displaying it.
Sounds like you either don't have PHP installed or you're not using a file extension which invokes the PHP engine - is your file called [Blah].php?
Some things to check:
You're serving the file from a web server (not locally)
The server has PHP installed
Your webserver is configured to use the PHP engine to handle the file type you're using (usually .php or .php4 or similar)
creating a new file with just <?php phpinfo(); ?> and serving it should give you lots of info about your PHP install.
If you have access to the server, you should be able to run PHP from the command line/shell
I'm trying to use a PHP include for the first time. I'm reasonably familiar with HTML, and new to PHP.
I've put the HTML for my header in a separate PHP file, and am trying to call it from http://www.kirtancentral.com/index-test.html. You can see I attempted it in a bunch of formats, I was of course hoping this one would do the trick:
<?php include("/home/danielctucker/kirtancentral.com/includes/header.php"); ?>
Not sure what I'm doing wrong!
You have to make your web server execute the PHP before any PHP embedded in a page will work. The fact you can see the PHP when you View Source shows that this is not happening.
Most servers (which have PHP installed and enabled) will only look in files with a .php file extension for PHP code (although this can be configured otherwise).
Try changing from index.html to index.php. If that doesn't work, then you need to install and enable PHP (if you control the server) or change your hosting pacakage.
You do not have PHP enabled on your server.
Install/enable PHP
Also it is good practice to use a relative path to your PHP script:
<?php include("includes/header.php"); ?>
Of course, this will only work when you have PHP enabled on your server.
Radhe-Shyam! :)
I got my Xampp server running and can run my html in subdirectories now, as well (can't have spaces in the subdirectory names).
SSI Includes or PHP Includes:
Xampp says SSI is deactivated. Tried uncommenting the lines for includes, but it doesn't change the deactivation.
How do I activate SSI?
Then, how do I implement either SSI include statements or PHP include statements into my html to call up html files that include html, images, javascript and commands that call other javascript menu files?
I don't know if Xampp has a special way of activating SSI or not, but the normal Apache way should work.
The normal way to include files in SSI is
<!--#include virtual="/something/file.html" -->
where the url to the file is actually http://www.example.com/something/file.html .
PHP includes are pretty straightforward. Just name your file something.php and do this:
<?php include('path/to/file.php'); ?>
The file will be parsed by php so it can contain the standard mix of PHP/HTML tags or whatever other text you'd like.
If XAMPP says SSI are disabled by default, you need to edit your server configuration (not your .HTACCESS file) to change this. Otherwise, you could try installing a plugin for your server to fix the issue.
Hope this helps!
~ Nate.