【问题标题】:Using Inline PHP with $_Session将内联 PHP 与 $_Session 一起使用
【发布时间】:2012-05-01 09:41:17
【问题描述】:

我再次尝试使用我的 PHP,但我遇到了一些内联问题。我正在使用我在http://www.1stoptutorials.com/Membership_Course.html 学到的成员脚本。

我的表有以下字段:userid、first_name、last_name、email_address、username、password、dob、guardianid、user_level、signup_date、last_login、activated。

我想要做的是在用户登录时使用我的表中的数据,但由于某种原因,我能够访问的只是名字和姓氏字段。其他人都没有工作。

这是我当前在标题中的 PHP

<?php
require_once ('verify.php'); 
// Start output buffering:
ob_start();
// Initialize a session:
session_start();
// If no first_name session variable exists, redirect the user:
if (!isset($_SESSION['first_name'])) {  
$url = BASE_URL . ''; // Define the URL.
ob_end_clean(); // Delete the buffer.
header("Location: $url");
exit(); // Quit the script. 
}
?>

它在底部被关闭。现在登录,他们使用他们的用户名和密码,但我想知道为什么我只能使用他们的名字和姓氏?另外我如何嵌入内联?我目前正在使用以下内容。

<p style="color:White;">
  Welcome 
  <strong>
    <a href="profile.php?id=<? echo $_SESSION['userid'] ?>" style="font-family:Arial, Helvetica, sans-serif;color:White;">
      <? echo $_SESSION['first_name'] ." ". $_SESSION['last_name'] ?>
    </a>
  </strong>
  &nbsp;&nbsp;-&nbsp;&nbsp;Home&nbsp;&nbsp;|&nbsp;&nbsp;
  <a href="photo.php" class="link">Photos</a>
  &nbsp;&nbsp;|&nbsp;&nbsp;
  <a href="video.php" class="link">Videos</a>
  &nbsp;&nbsp;|&nbsp;&nbsp;
  <a href="logout.php" class="link">Log Out</a>
</p>

当然,我的输出页面中只会出现名称,而不是 id 或任何其他字段。

有人可以帮忙吗?或者我需要发布更多信息吗?

或者谁能推荐一个更好的登录脚本?

【问题讨论】:

  • 感谢您的帮助。我是一名 ASP 开发人员,所以到目前为止 PHP 对我来说并不是那么好。有什么有用的可以补充吗?
  • 这里没有足够的信息来回答您的问题。您如何将数据放入 $_SESSION?它来自哪里?
  • 我不确定。我是 PHP 新手,只是使用这个模板作为一种学习方式。我实际上想从 cookie 中使用,但需要解决这个问题

标签: php session login


【解决方案1】:

仅仅因为你学到的脚本告诉你只使用first_name 并不意味着你必须继续使用同样的东西。您可以使用在存储数据时使用的任何字段。最有效的方法是存储user_id

关于内联部分,值得商榷。有些人喜欢内联 PHP,有些人喜欢内联 HTML。使用让你更舒服的东西。

【讨论】:

  • 感谢您的建议。 :)
【解决方案2】:

我想知道为什么我只能使用他们的名字和姓氏?

因为verify.php 中的某些代码不会在会话中存储任何其他内容,我相信。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-08-23
    • 1970-01-01
    • 2023-03-06
    • 1970-01-01
    • 1970-01-01
    • 2012-03-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多