php - 将用户名保存为变量,然后在其他地方回显

时间:2016-01-12 01:49:01

标签: php username

我正在尝试修改论坛的登录表单,以便在登录后,它会“欢迎使用用户名”。

这是signin.php内容的一大块 -

echo '<div id="username">Welcome, '+$USERNAME+'</div>';

然后,在index.php中,我想我会添加类似(伪代码)的行 -

#if defined(_STDEXT_BEGIN) && !(defined(_MSC_VER) && (_MSC_VER < 1400 || _MSC_VER >= 1600)) && !defined(_STLPORT_VERSION)
    stdext::unchecked_mismatch
#else
    std::mismatch
#endif
#if _MSC_VER >= 1600
    (stdext::make_unchecked_array_iterator(scan)+3, stdext::make_unchecked_array_iterator(scanEnd), stdext::make_unchecked_array_iterator(match)+3).first - stdext::make_unchecked_array_iterator(scan));
#else
    (scan+3, scanEnd, match+3).first - scan);
#endif

我试过玩$ _SESSION ['用户名'],但我在php中没用,所以任何指导都会非常有用,谢谢。

1 个答案:

答案 0 :(得分:0)

您可以使用会话

在您的登录脚本中:

Collecting mysql-python
/Library/Python/2.7/site-packages/pip/_vendor/requests/packages/urllib3/util/ssl_.py:90: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning.
  InsecurePlatformWarning
  Downloading MySQL-python-1.2.5.zip (108kB)
    100% |████████████████████████████████| 110kB 1.8MB/s
    Complete output from command python setup.py egg_info:
    sh: mysql_config: command not found
    Traceback (most recent call last):
      File "<string>", line 20, in <module>
      File "/private/tmp/pip-build-ev74Js/mysql-python/setup.py", line 17, in <module>
        metadata, options = get_config()
      File "setup_posix.py", line 43, in get_config
        libs = mysql_config("libs_r")
      File "setup_posix.py", line 25, in mysql_config
        raise EnvironmentError("%s not found" % (mysql_config.path,))
    EnvironmentError: mysql_config not found

    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /private/tmp/pip-build-ev74Js/mysql-python

...

session_start();

您要显示的位置:

}else{
    Users_LoggedIn($user, isset($_POST['remember_me']));

    $_SESSION['Username'] = $user['username'];

    header('Location: '.FORUM_URL); // redirects to index.php
    exit;
}

此处有更多示例:http://php.net/manual/en/session.examples.php