2017-02-04 3 views
0

私はJoomlaベースのサイトを実行しており、インターコムがphp経由でログインしたユーザーデータを取得しようとしています。正しい式は、これらの線何のためにあるのか、誰を知っている(またはどこ私はそれを見つけることができますか?):PHP returnログインユーザー

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

2番目の質問:何が起こるだろうことは何もログインしたユーザーがなかったですが?

FYI:残念ながら、私は残念ながら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> 

答えて

0

あなたが直接引くことができませんJoomlaからIntercomへのデータは、joomlaフレームワークを呼び出してユーザープロパティにアクセスする必要があります。あなたが任意のユーザーでログインして持っていけないあなたがそうも同様にあなたがもしelse文を使用して、コードを変更することができ、ユーザーID = 0またはゲストを取得する場合まず、あなたは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; 

に接続して取得するために、このコードを使用する必要があります。 if($user->id ==0)など