-1

I have some problem on my work. I have PHP file and want to include his file to HTML page. I used include_once()..

I just want to know, why can't include_once() run on my HTML page?

Thank you...

Vidal
  • 2,306
  • 2
  • 11
  • 27
8727
  • 73
  • 7
  • You are talking about a file with the suffix `.htm`/`.html`? Well those simply do not get parsed as PHP in default configuration. – misorude Aug 09 '19 at 12:15
  • is the page saved with `.html` or `.htm` file extension? Have you got the path to the include correct? Without your code and a clearer understanding of the problem we cannot help – Professor Abronsius Aug 09 '19 at 12:17
  • with .html this my code Tutorial Republic – 8727 Aug 09 '19 at 12:18
  • unless you have done some trickery with your webserver configuration so that it will process files saved as `.html` or `.htm` to be executed like `.php` files are then you cannot include php files as you are trying. – Professor Abronsius Aug 09 '19 at 12:29

1 Answers1

3

include_once is a php command and it cannot be run with HTML.

The file extension of your page must end in .php so that your server knows to read the instructions with the php processor, OR you have to have some directives written into your .htaccess file to allow the server to do some fancy work.

Save your file as .php and include the file like this.

<h1>My HTML</h1>

<?php include_once ('myFile.php') /?>

<p>More Html</p>

PHP can parse the HTML!

Will
  • 379
  • 1
  • 11
  • What if I save my file as .html? – 8727 Aug 09 '19 at 12:20
  • You need to set us the server to parse .html with the php parser. The instructions are different for different server OS. What OS do you use? – Will Aug 09 '19 at 12:22
  • I use windows...can you help me? – 8727 Aug 09 '19 at 12:24
  • https://stackoverflow.com/questions/14021203/how-to-run-php-code-in-html-file-on-windows-server – Will Aug 09 '19 at 12:26
  • @8727 Don't do that, rather rename your html file to php. Because if you decide to move your page to other hosting, you can forget to set handler and you could accidentaly send your code to the visitor ... – Pavel Třupek Aug 09 '19 at 12:27
  • I personally agree with @PavelTřupek . I think you are over-complicating the situation unnecessarily – Will Aug 09 '19 at 12:29
  • I appreciate all those answer, thank you so much... – 8727 Aug 09 '19 at 12:34