doty58493 2014-02-20 08:05
浏览 42
已采纳

微登录php玩具$ username在其他页面

i use phpoys micro login system to login and register users to my website but i cant figure out how i can display the $username in pages....

micro login script

I integrated this scrip in my website and it works great, but when i want to call $username, like in the login.php file for example in index.php the $username doesnt exist?

when i place echo $_SESSION['userName'] ; i get the username, bu if it was $username i could integrate his in other functions of my website. Is this solvable to read $username not only on he login.php script?

on he login page $username is called like this

if (isset($_POST['submitBtn'])){
    // Get user input
    $username = isset($_POST['username']) ? $_POST['username'] : '';
    $password = isset($_POST['password']) ? $_POST['password'] : '';
}
  • 写回答

1条回答 默认 最新

  • dongtang5229 2014-02-20 08:14
    关注

    Once you've logged in you'll be able to access the username from the $_SESSION variable.

    To check whether the $_SESSION data has been set, use the function isset.

    if (isset($_SESSION['userName'])) {
       echo $_SESSION['userName'];
    }
    

    This will only display the username if you are logged in. To use the session data across onto other pages, be sure to place session_start(); up the top.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 抖音咸鱼付款链接转码支付宝
  • ¥15 ubuntu22.04上安装ursim-3.15.8.106339遇到的问题
  • ¥15 求螺旋焊缝的图像处理
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?
  • ¥15 网络通信安全解决方案
  • ¥50 yalmip+Gurobi
  • ¥20 win10修改放大文本以及缩放与布局后蓝屏无法正常进入桌面
  • ¥15 itunes恢复数据最后一步发生错误
  • ¥15 关于#windows#的问题:2024年5月15日的win11更新后资源管理器没有地址栏了顶部的地址栏和文件搜索都消失了