簡體   English   中英

PHP返回登錄用戶

[英]PHP return Logged In User

我運行了一個基於Joomla的網站,並且試圖通過php獲取對講機來登錄用戶數據。 有誰知道這些行的正確公式是什么(或者在哪里可以找到它?):

<?php echo $current_user->name ?>
<?php echo $current_user->email ?>

第二個問題:如果沒有登錄用戶會發生什么?

僅供參考:不幸的是,我的PHP不流利!

完整代碼:

<script>
  window.intercomSettings = {
    app_id: "*****",
    name: "<?php echo $current_user->name ?>", // Full name
    email: "<?php echo $current_user->email ?>", // Email address
    created_at: <?php echo strtotime($current_user->created_at) ?> // Signup date as a Unix timestamp
  };
</script>
<script>(function(){var w=window;var ic=w.Intercom;if(typeof ic==="function"){ic('reattach_activator');ic('update',intercomSettings);}else{var d=document;var i=function(){i.c(arguments)};i.q=[];i.c=function(args){i.q.push(args)};w.Intercom=i;function l(){var s=d.createElement('script');s.type='text/javascript';s.async=true;s.src='https://widget.intercom.io/widget/unvfagbb';var x=d.getElementsByTagName('script')[0];x.parentNode.insertBefore(s,x);}if(w.attachEvent){w.attachEvent('onload',l);}else{w.addEventListener('load',l,false);}}})()</script>

獲取用戶對象:(將此行放在<script>標記之前)

$current_user = JFactory::getUser();

另請參閱: https : //docs.joomla.org/Accessing_the_current_user_object

您無法直接將數據從Joomla提取到對講機,需要調用joomla框架並訪問用戶屬性。 首先,您需要使用此代碼連接到Joomla

<?php
define( '_JEXEC', 1 );
define( 'DS', DIRECTORY_SEPARATOR );
define('JPATH_BASE', "C:\Vertrigo\www\joomla" );// Your Joomla Installation folder
//Next call the mandatory framework files
require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' );
require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' );
//Initialise the mainframe
$mainframe = JFactory::getApplication('site');
$mainframe->initialise();
//get user details
$user = JFactory::getUser();
//To get current logged in user
$current_user->name = $user->username;
$current_user->email =$user->email;

如果您沒有任何登錄用戶,則會得到userid = 0或guest,因此同樣可以使用if else語句更改代碼。 if($user->id ==0)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM