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

我与影子孤独终老i 提交于 2019-12-24 13:27:43

问题


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.


回答1:


Please change file extention from .html to .php




回答2:


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




回答3:


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



来源:https://stackoverflow.com/questions/14029824/php-tags-in-html-files-dont-work-in-webmatrix

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!