如何从html/jquery页脚的会话中打印php变量?


How can I print a php variable from a session in the footer of an html/jquery page?

我目前正试图通过写它不工作来使用JQuery页脚内的打印。相反,什么也没有出现。在之前的php页面中,我使用…

将其存储到会话中。
session_start(); 
$_SESSION['username'] = $_POST['username'];

我的HTML页面代码如下…

<?php session.start(); 
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Food For Thought</title>
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.0a1/jquery.mobile-1.0a1.min.css" />
<script src="http://code.jquery.com/jquery-1.4.3.min.js"></script>
<script src="http://code.jquery.com/mobile/1.0a1/jquery.mobile-1.0a1.min.js"></script>
</head>
<body>
<div data-role="page" id="page1">
    <div data-role="header" id = "hdrMain" name = "hdrMain" data-nobackbtn = "true">
        <h1>Food for Thought</h1>
        </div><!-- /header -->
    <div data-role="content" align ="center">
            <a href="game.html" rel="external" data-role="button">Play</a>
            <a href="profile.html" data-role="button">Profile</a>
            <a href="index.html" data-role="button">Logout</a> 
        </div><!-- /content -->
        <div data-role="footer">
        <p>Logged in as: <?php print $_SESSION["username"]; ?> </p>
        </div>
</div>
</body>
</html>

谢谢你的帮助。

编辑:问题是,我试图运行php代码结束的文件。html而不是。php。谢谢大家的帮助。

你的HTML页面有:

session.start();

应该是

session_start();