-1

i have to include menu.php file in main.php

this is what i have done up till now.

main.php

<html>
   <body>

      <?php include("menu.php"); ?>
      <p>This is an example to show how to include PHP file!</p>

   </body>
</html>

and menu.php

<a href="http://www.tutorialspoint.com/index.htm">Home</a> - 
<a href="http://www.tutorialspoint.com/ebxml">ebXML</a> - 
<a href="http://www.tutorialspoint.com/ajax">AJAX</a> - 
<a href="http://www.tutorialspoint.com/perl">PERL</a> <br />

both files are in same directory. when i open main file in browser is showes

main.php open in browser

and when i right click on page and view page source it shows

page source

any idea what im missing here . any suggestions

M Hamza Javed
  • 1,269
  • 4
  • 17
  • 31

2 Answers2

2

You cant open PHP-Files in a browser, without a server. PHP is a script language, which need to be interpreted by a server.

This is the reason, why your php-code is ignored, while your html-code is rendered properly.

Phillip K
  • 237
  • 1
  • 8
1

From your question what i understand is that you haven't set up a server and main.php file is not accessed through server URL(like localhost/main.php if you are working on local server). PHP is a general-purpose scripting language which is executed on the server. Server Generates HTML code corresponding to the script and send it to client (Here Your Browser). Here you are trying to open the main.php file using browser which renders the HTML code on the page, not php code 'include("main.php")' . So in order to work properly you have to follow this (http://howtoubuntu.org/how-to-install-lamp-on-ubuntu) on Ubuntu or in windows this (https://www.sitepoint.com/how-to-install-php-on-windows/) (there are lots of other tutorials available you don't have to follow these). ie, Setup a server like apache and move this files to root folder and access the main.php through the server.

Nag
  • 43
  • 6