Member Avatar for chudapati09

I can't get the following code to work correctly:

<html>
<head>
<title>test</title>
</head>
<body>
<?php
$ip = $_SERVER['REMOTE_ADDR'];
echo "<h1>" . $ip . "</h1>";
?>
</body>
</html>

It outputs this:

" . $ip . ""; ?>

But when I create a php file and throw the php into it I get the result I want:

<?php
$ip = $_SERVER['REMOTE_ADDR'];
echo "<h1>" . $ip . "</h1>";
?>

Result:

(My IP Address)

Hey i checked your code..It's working fine ...it's showing the my IP ....What's the problem??

You are probably saving the the top code as a .html file, but you need to save it as a .php file if you are going to include php in it. The html will all still work perfectly fine, but you'll be able to execute php inside of the html now.

Member Avatar for diafol

As ct says, .html or .htm files won't usually run php. You can set them to do so with in .htaccess file:

AddType application/x-httpd-php .html

Why do you need to save it as *.html?? I'd just use the *.php extension.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.