Wednesday, April 20, 2011

How to use PHP code in HTML file

Many places, we feel that we can give better result if it would possible to use PHP code instead of javascript code in HTML page. Below is the way to use php code in the html page.

Html file name is "abc.html" :
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Use PHP in HTML file</title>
</head>

<body> 
<!-- We can also pass the parameters to PHP as query string -->
<script src="xyz.php?uid=10&pid=string value"></script>
</body>
</html>
PHP file name is "xyz.php":
<?php
header("application/javascript");
$uid=$_GET['uid'];$pid=$_GET['pid'];
$ip=$_SERVER['REMOTE_ADDR'];
$mytime=date('m-d-Y H:i:s');
echo "document.write('Your IP is <b>$ip</b><br />Server date and time is <b>$mytime</b>');";
echo "document.write('<br />$pid');";
?>

Output :
Your IP is 127.0.0.1
Server date and time is 04-27-2011 01:01:44
string value

 Please feel free to provide your valuable feedback.

No comments:

Post a Comment

Thanks for your valuable comments.

Important queries based formulas to watch performance of a MySQL based application

(1) Session Vs global status variables value select G.variable_name,G.variable_value GlobalValue,S.variable_value SessionValue from (selec...