【问题标题】:Send a variable to other page (Send a message) [closed]将变量发送到其他页面(发送消息)[关闭]
【发布时间】:2022-01-09 18:15:51
【问题描述】:

假设我已经完成了注册和登录页面,有没有办法将变量从注册发送到登录?

我的目标是提醒用户该帐户已创建。它应该如下所示: Result

【问题讨论】:

  • 是的,有多种方式,例如:使用 URL 参数、使用会话、使用 cookie。你都尝试了些什么?你被困在哪里了?
  • 我尝试使用“GET”在 php 中搜索全局变量之类的东西
  • 更改页面后全局变量将无法生存
  • 一个 Cookie 可能吗?
  • 会话值可能更合适。

标签: php html bootstrap-4


【解决方案1】:

您可能想为此使用会话

注册脚本:

//Start session, you need to do this to use session variables
    session_start();
//Make the session variable
    $_SESSION['message']="Account has been created";

登录页面:

    <?php
                session_start();
//Checks if the variable is declared, makes sure you don't get a warning for missing variable
                if (isset($_SESSION['message'])) {
//You can add whatever CSS class you want to this with "<div class='{Class name}'>". $_SESSION['message'] ."</div>"
                    echo $_SESSION['message'];
                }
//Unset the variable, this makes sure you don't get the message again when you reload, if you're not using sessions anymore session_destroy(); is even better
                unset($_SESSION['message']);

【讨论】:

  • 非常感谢你救了我!
  • @rrenildopereiraa 没问题,只是在我的评论中注意到了一个关于如何添加 css 类的小问题。编辑了我的答案 你能否也将我的答案标记为正确,以防有人偶然发现这篇文章
  • 嗯,我明白了...我是新来的,所以我知道如何将其标记为正确
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-09-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-09-13
相关资源
最近更新 更多