简体   繁体   中英

passing get_current_user to session variable in 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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM