0

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)

4
Contributors
3
Replies
4
Views
6 Years
Discussion Span
Last Post by diafol
0

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.

Edited by ctaylo21: n/a

0

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.