duanji2014 2016-01-27 22:17
浏览 30

将get_current_user传递给php中的会话变量

I'm new at php and programming in general. I want to gather the user, host and IP address when a person loads my webpage and store it in session variables. I can see the values using

<?php
echo 'IP Address: ' . getHostByName(getHostName());
?>

<?php
echo gethostname() ;
?>

<?php
echo 'Username: ' . get_current_user();
?>

However, I don't seem to understand how I can then assign those values to session variables that I can then call in SQL queries to limit output based on the user variables. For instance, adding this to the PHP top code causing the form to fail to load:

 <?php
     session_start();     
     $_SESSION['username'] =   . get_current_user();
   ?>

I know I'm oversimplifying but I have spent hours researching the web looking for this answer which seems like it should be common place and of high value.

Thanks in advance.

  • 写回答

1条回答 默认 最新

  • dongqian2021 2016-01-27 22:38
    关注

    you got syntax error. The dot in the second line.

     <?php
         session_start();     
         $_SESSION['username'] =  get_current_user();
       ?>
    

    and make sure you put the session_start(); before any output.

    评论

报告相同问题?

悬赏问题

  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探