PHP include format for Kirtan Central website - php

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! :)

Related

php include isnt working

I have a server, and I decided to update the OS, php was also updated from php5 to php7. In the web pages, I have includes to get layout info.
like this:
<html><body>
<?php include "scripts/sidebar.php";?>
</body></html>
(For example).
The php files individually work, but the web pages do not INCLUDE the files in the include statements. Formerly, this had been working. I have looked for errors in /var/log/nginx/error.log and /var/log/nginx/access.log, there are none.
There are also no errors in /var/log/php7.0-fpm.log
I tried changing the php.ini file variable "include_path" to point to the location of the scripts, (and reload nginx and php), but this had no effect.
I tried setting "allow_url_include = On" as described in the PHP documentation: http://php.net/manual/en/filesystem.configuration.php
After restarting php, and nginx, this seemed to have no effect.
What can I do to make the <?php include 'scripts/sidebar.php';?> function work?
if you can use like this.
include_once './test.php';
all files in same directory
You have not mentioned your file name from where you are including the php file, if your file extension is php then it will work.
Try to use
<?php include_once(dirname(__FILE__)."/scripts/sidebar.php"); ?>

visual studio does not recognize php

i added php code in my cshtml view under asp.net mvc.
<body>
<?php echo"hello";?>
...
however it seems that vs does not understand that it's php and when I inspect element, the php code was automatically commented out.
<!--?php echo"hello";?-->
how can I solve this? I have already installed php tool extension in vs.
To run php script, you need to have .php files, or it won't be recognized.
To enable the script to be recognized as php without changing file suffix, add config files depending on the server you are using. (most likely Apache/IIS)

PHP in html not parsing

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).

simple php script

New to php and taking a class for it. Bought php6 and mysql 6 bible to get started. Of course the hello world script is the first you get and it doesn't show. It just reads part of my script and I'm not sure the problem. Link to test - http://harden6615.com/
I am using a hosted server I bought for class, but I have also check it using MAMP. I figured my script is wrong, but I have copied and pasted and still no Hello World. Any suggestions?
What I copied:
<?php
print("Hello, World<BR />\n");
phpinfo();
?>
Safe the file as index.php instead of index.html.
Checklist:
host allows PHP
file has .php extension
file was edited with a programmer's text editor (not word/wordpad under windows or TextEdit under Mac) because some encode <, > symbols when saving the file
Well actually it isn't, try to use just <?php phpinfo(); ?> If this doesn't show anything - take a look at your webhost if he supports php...
There are a few reasons why PHP may not be being executed.
The most basic error is saving the file as a .html file instead of .php. Make sure you use the correct extension on your file.
Next, make sure your webhost supports PHP. Most free hosts do not, so it's always a good idea to double-check.
There is nothing wrong with your code. If the above two solutions didn't help, try contacting your webhost and asking them why PHP isn't working for you.

PHP scripts are not executing on some of the pages

One of my php website is not working fully. Its showing me only home page and when i try to open up any present link it shows me the php code of the file that is called in for that link.
PHP is installed properly. Same server is hosting more than 10 other websites of PHP. No .htaccess parameters etc.. Same site is working on some other server with same settings and same code... I am unable to find the reason..
Make sure you are using
<?php .. ?>
tags everywhere, you might know this, but I am pointing it out just in case.
In earlier versions, apache would pick up and compile anything with
<? ... ?>
tags and it was a mistake since it was getting confused with the xml file versions.
so they changed it to complie only stuff in
<?php ... ?>
Also, again, you might know this, make sure you are hosting it on a php supported server.
There is also this "feature" that you can configure in your .htaccess to ignore certain files. make sure your .htaccess is not having exceptions for php compilation.
I cant think of anything else right now :)
Make sure everything of your PHP-Code is between the php tags like
iamserious has written upstairs.
Make sure you're filename's extension is .php index.php for example.
Make sure it's in the path to the file is ok!
Make sure you're webserver is working perfectly with PHP!

Categories