【问题标题】:How can I print a php variable from a session in the footer of an html/jquery page?如何从 html/jquery 页面页脚的会话中打印 php 变量?
【发布时间】:2011-11-04 13:10:21
【问题描述】:

我目前正在尝试在 JQuery 页脚中使用 print,但它不起作用。相反,什么也没有出现。在早期的 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 结尾。感谢所有试图提供帮助的人。

【问题讨论】:

  • 这个页脚与 jquery 有什么关系?
  • 如果保存为 .html 的页面比 php 标记不起作用,并且您的会话开始语句在 html 页面中是错误的,它应该是 session_start();
  • 我改了,还是不行。页脚只是使页脚(jquery mobile 中的黑条)说“登录为:用户名”,除了用户名没有显示。

标签: php html session jquery-mobile


【解决方案1】:

嗯,你的 HTML 页面有:

session.start();

应该是

session_start();

【讨论】:

  • 改了还是不行谢谢指正。
  • 并且您确定每当此人登录时 $_SESSION['username'] 都会填充内容?
  • 是的,在早期的 php 页面中,我使用了 Print_R ($_SESSION);它输出用户名中的值。
  • 并且是同一个域(注意:www.domain.com 和 domain.com 充当不同的域)?除此之外,没有理由不通过页面进行会话。
  • 感谢您的帮助。事实证明,您无法在 html 文件中编写 php 代码并让它运行。我不得不重命名文件 .php
猜你喜欢
  • 2020-07-29
  • 1970-01-01
  • 2013-05-19
  • 2015-02-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-12-29
  • 2018-09-21
相关资源
最近更新 更多