简体   繁体   English

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

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

I currently am trying to use print inside of the JQuery footer by writing it is not working. 我目前正在尝试使用JQuery页脚内部的print来写它不起作用。 Instead nothing shows up. 相反没有出现。 In the earlier php page I stored it into the session using... 在早期的php页面中,我使用...将其存储到会话中

session_start(); 
$_SESSION['username'] = $_POST['username'];

my code in my html page is as follows... 我的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>

Thank you any help is appreciated. 谢谢任何帮助表示赞赏。

Edit: Problem was that the file I was trying to run php code ended in .html instead of .php. 编辑:问题是我试图运行PHP代码的文件以.html而不是.php结尾。 Thank you all who tried to help. 谢谢所有试图提供帮助的人。

Well, you're HTML page has: 那么,你的HTML页面有:

session.start();

it should be 它应该是

session_start();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM