how to write a php embed code that calls another php in a html page


How to write a PHP code (using public id) that can embed into HTML file (abc.html) when we open that HTML file that has to call another PHP file(there we can insert stats of that file into database).

if i cannot do this in php, is there any other way except renaming html file extension to php extension




Do you mean this?

<?php echo "test"; ?>


usingexec('php foo.php'); to call another php file?


including another php file using

include 'foo.php';
require 'anotherfoo.php';


Or you can use ajax to call a .php file to the abc.html file.

    type: 'POST',
    url: 'foo.php',
    data: 'username=myuser&id=123456',
    success: function(result) {
        /* do something with result here */

You need to have the jquery library which can be downloaded here.




If I understood you correctly, you're wanting to use the PHP include function. You may also want to check PHP's include_once function depending on what you're doing.

You will need to make sure the "HTML" page is actually a PHP page. If your page is already written and exists as HTML and not PHP, you will need sufficient privileges to edit the MIME types and associate .html (or whatever file extention you're using) with PHP processes on the server side. Otherwise you will need to recreate the page as a PHP page using the .php file extension.

For example you may have code like this in the initial file:

<!DOCTYPE html>
<TITLE>My Web page title</TITLE>
<p>Welcome to my website</p>
<?php include('this_page.php'); ?>

This will call the this_page.php file and allow it to execute any scripts within it.

I hope this helps you.




You cannot embed PHP into an web page, PHP is a server side scripting language, which means it is only executed on the server. The user does not even know whether you are using PHP (except for the .php extension, but that means nothing.)

You can however call a PHP script from another PHP script, e.g.

exec('php script.php');



include(other_file.php), include_once(other_file.php), require(other_file.php), require_once(other_file.php) ...


use an iframe or exec(other_file.php)




Within your HTML you could use a tag such as an image or script to call your php script. This could be useful if you want your PHP to do something simple such as to increment a counter in a database.

<img src="/path/to/script.php" alt="" />

This is trivial as long as you don't want the executing PHP to return anything visible within the page. If you use an image tag, after you've finished with whatever processing you are doing, it might be best to have your PHP return an image of some sort - but it could be as trivial as a 1px by 1px transparent gif.

$im = file_get_contents('/path/to/your/image/transparent.gif');
header('content-type: image/gif');
echo $im;

People are also looking for solutions to the problem: php - Validate email and ban certain domains


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.