user1009573
user1009573

Reputation: 113

Php tags in .html files don't work in WebMatrix

I've been learning web development and the book I am learning from is using php tags within html files but they don't work for me, here is my header page:

<!DOCTYPE html>

<html lang="en">
<head>
    <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
    <title><?php echo $page_title; ?></title>
    <style type="text/css" media="all">@import "./includes/layout.css";</style>
</head>
<body>
    <a href="index.php" class="logo"> <img src="Includes/Images/NameIconSplash.png" /></a>
    <div id="wrapper">
        <div id="content">
            <div id="news">
                <div id="nav">
                    <ul>
                        // Tags don't work here
                        <?php
                            if ( (isset($_COOKIE['user_id'])) && (!strpos($_SERVER['PHP_SELF'], 'logout.php')) ) 
                            {
                                echo '<li><a href="logout.php">                                           Logout</a></li>'
                            } 
                            else 
                            {
                                echo '<li><a href="login.php">                                            Login</a></li>'
                                echo '<li><a href="register.php">                                         Register</a></li>'
                            }
                        ?>




                    </ul>
                </div>

The php code is just normal black text but it recognises the html code within the php tags. Does someone know why it doesn't recognise them?

Thankyou in advance.

Upvotes: 1

Views: 1056

Answers (3)

pkachhia
pkachhia

Reputation: 1932

If you want to use php code you have to use .php extension, so change extension to .php.

Upvotes: 1

Bhuvan Rikka
Bhuvan Rikka

Reputation: 2703

Web servers are configured to detect the file type by looking at the extension. By default it will route .php files through the PHP interpreter, and .html files will be served directly to the end user. You can configure this behaviour via the server's config file, or the local .htaccess file for the individual web directory.

RemoveHandler .html .htm
AddType application/x-httpd-php .php .htm .html

Do this if you really don't want to save your files as .php. Or else saving your files with .php does the job

Upvotes: 1

sandip
sandip

Reputation: 3289

Please change file extention from .html to .php

Upvotes: 1

Related Questions