Jump to content

Getting user details in PHP - \IPS\Session\Front::i();


Simon Harvey

Recommended Posts

Posted

Hello,

I am trying to put together a page outside of IPB on the same server that detects if a user is logged in or not.

I am using the code:

require_once '/{absolute path to IPB}/init.php';

/* Initiate the session to verify who this user is */
\IPS\Session\Front::i();

echo 'Name: ' . \IPS\Member::loggedIn()->name;

But this is returning strange data:

Name: 8b21f99914133482083efd11a04e0584

Do you know what I am doing wrong?  Do I need to process the returned value in someway to receive the correct information?

When I try to get the user ID nothing is returned:

echo $userid = \IPS\Member::loggedIn()->member_id;

I am doing this while logged in as administrator.


Any advice would be great.

Thanks a lot.

Posted

No it should be the member's name. Have you tried to dump the whole object?

var_dump(\IPS\Member::loggedIn());

What about the result of \IPS\Member::loggedIn()->member_id ?

 

Also you may want to post in "Development Assistance" next time :).

Posted

Thanks a lot.  Yes sorry, I should have posted there - but I'll stick with this thread now I've started it.

This is the dump:

object(IPS\Member)#8 (29) { ["_followData"]=> NULL ["_previousPhotoType":protected]=> NULL ["_group"]=> NULL ["restrictions":protected]=> NULL ["modPermissions":protected]=> NULL ["calculatedLanguageId":protected]=> int(1) ["markers"]=> array(0) { } ["markersResetTimes":protected]=> array(0) { } ["haveAllMarkers":protected]=> bool(false) ["defaultStreamId":protected]=> bool(false) ["changedCustomFields"]=> array(0) { } ["previousName":protected]=> NULL ["_groups":protected]=> NULL ["_socialGroups":protected]=> NULL ["sessionData":protected]=> NULL ["_lang":protected]=> object(IPS\Lang)#7 (18) { ["outputStack"]=> array(18) { ["03545700c3262969e849acdf3dc4c841"]=> array(3) { ["key"]=> string(40) "__indefart_content_record_comments_title" ["options"]=> array(0) { } ["vle"]=> bool(true) } ["517fa07bed6da0eb82f6994fe147159c"]=> array(3) { ["key"]=> string(39) "__indefart_content_record_reviews_title" ["options"]=> array(0) { } ["vle"]=> bool(true) } ["665d96ae1390a53f9d886d87de6a570b"]=> array(3) { ["key"]=> string(20) "content_db_lang_ia_1" ["options"]=> array(0) { } ["vle"]=> bool(true) } ["4c9e1da9f74cd448b0b2b872c7b71719"]=> array(3) { ["key"]=> string(38) "__defart_content_record_comments_title" ["options"]=> array(0) { } ["vle"]=> bool(true) } ["0d731d3fa1327b71c66c3a1baca96036"]=> array(3) { ["key"]=> string(37) "__defart_content_record_reviews_title" ["options"]=> array(0) { } ["vle"]=> bool(true) } ["8a9a08fc1feefec59d9e9199cbcc2871"]=> array(3) { ["key"]=> string(20) "content_db_lang_sl_1" ["options"]=> array(0) { } ["vle"]=> bool(true) } ["f0ac85ca90cf1e06013c801e0c12bcd4"]=> array(3) { ["key"]=> string(20) "content_db_lang_su_1" ["options"]=> array(0) { } ["vle"]=> bool(true) } ["9ef07e19b57ef281ac5948f886b3b404"]=> array(3) { ["key"]=> string(28) "content_record_comment_title" ["options"]=> array(1) { ["sprintf"]=> array(1) { [0]=> string(32) "f0ac85ca90cf1e06013c801e0c12bcd4" } } ["vle"]=> bool(false) } ["81509492f4f38388f3545cca4ee8f0c6"]=> array(3) { ["key"]=> string(27) "content_record_review_title" ["options"]=> array(1) { ["sprintf"]=> array(1) { [0]=> string(32) "f0ac85ca90cf1e06013c801e0c12bcd4" } } ["vle"]=> bool(false) } ["69af078a084b0117ae0f038fe4dbe5ac"]=> array(3) { ["key"]=> string(29) "content_record_comments_title" ["options"]=> array(1) { ["sprintf"]=> array(1) { [0]=> string(32) "f0ac85ca90cf1e06013c801e0c12bcd4" } } ["vle"]=> bool(false) } ["7b25cc64c680becb1195884788c83f2b"]=> array(3) { ["key"]=> string(32) "content_record_comments_title_lc" ["options"]=> array(1) { ["sprintf"]=> array(1) { [0]=> string(32) "8a9a08fc1feefec59d9e9199cbcc2871" } } ["vle"]=> bool(false) } ["5cbac280ceb31c4fc45e1306dbf17011"]=> array(3) { ["key"]=> string(28) "content_record_reviews_title" ["options"]=> array(1) { ["sprintf"]=> array(1) { [0]=> string(32) "f0ac85ca90cf1e06013c801e0c12bcd4" } } ["vle"]=> bool(false) } ["50f5e79e688560bd2fe68d8f12b8b9c2"]=> array(3) { ["key"]=> string(31) "content_record_reviews_title_lc" ["options"]=> array(1) { ["sprintf"]=> array(1) { [0]=> string(32) "8a9a08fc1feefec59d9e9199cbcc2871" } } ["vle"]=> bool(false) } ["8de3f734a5616754fea864a94c0ac34e"]=> array(3) { ["key"]=> string(20) "content_db_lang_pu_1" ["options"]=> array(0) { } ["vle"]=> bool(true) } ["9603fc099cd86d769b58819fcd615788"]=> array(3) { ["key"]=> string(20) "content_db_lang_pl_1" ["options"]=> array(0) { } ["vle"]=> bool(true) } ["1f7a40a0196146c769a48f490ab01cc6"]=> array(3) { ["key"]=> string(15) "content_field_1" ["options"]=> array(0) { } ["vle"]=> bool(true) } ["ee5872f83a815355414cbb9bce87da55"]=> array(3) { ["key"]=> string(15) "content_field_2" ["options"]=> array(0) { } ["vle"]=> bool(true) } ["07fbabcdee6eadffe8e6b5a44f0d9867"]=> array(3) { ["key"]=> string(5) "guest" ["options"]=> array(0) { } ["vle"]=> bool(true) } } ["wordsLoaded":protected]=> bool(false) ["locale"]=> array(18) { ["decimal_point"]=> string(1) "." ["thousands_sep"]=> string(1) "," ["int_curr_symbol"]=> string(4) "GBP " ["currency_symbol"]=> string(2) "£" ["mon_decimal_point"]=> string(1) "." ["mon_thousands_sep"]=> string(1) "," ["positive_sign"]=> string(0) "" ["negative_sign"]=> string(1) "-" ["int_frac_digits"]=> int(2) ["frac_digits"]=> int(2) ["p_cs_precedes"]=> int(1) ["p_sep_by_space"]=> int(0) ["n_cs_precedes"]=> int(1) ["n_sep_by_space"]=> int(0) ["p_sign_posn"]=> int(1) ["n_sign_posn"]=> int(1) ["grouping"]=> array(2) { [0]=> int(3) [1]=> int(3) } ["mon_grouping"]=> array(2) { [0]=> int(3) [1]=> int(3) } } ["codepage"]=> NULL ["words"]=> array(17) { ["__indefart_content_record_comments_title_1"]=> string(32) "03545700c3262969e849acdf3dc4c841" ["__indefart_content_record_reviews_title_1"]=> string(32) "517fa07bed6da0eb82f6994fe147159c" ["__indefart_content_db_lang_su_1"]=> string(32) "665d96ae1390a53f9d886d87de6a570b" ["__defart_content_record_comments_title_1"]=> string(32) "4c9e1da9f74cd448b0b2b872c7b71719" ["__defart_content_record_reviews_title_1"]=> string(32) "0d731d3fa1327b71c66c3a1baca96036" ["__defart_content_db_lang_su_1"]=> string(32) "8a9a08fc1feefec59d9e9199cbcc2871" ["content_record_comments_title_1"]=> string(32) "9ef07e19b57ef281ac5948f886b3b404" ["content_record_reviews_title_1"]=> string(32) "81509492f4f38388f3545cca4ee8f0c6" ["content_record_comments_title_1_pl"]=> string(32) "69af078a084b0117ae0f038fe4dbe5ac" ["content_record_comments_title_1_pl_lc"]=> string(32) "7b25cc64c680becb1195884788c83f2b" ["content_record_reviews_title_1_pl"]=> string(32) "5cbac280ceb31c4fc45e1306dbf17011" ["content_record_reviews_title_1_pl_lc"]=> string(32) "50f5e79e688560bd2fe68d8f12b8b9c2" ["content_db_lang_su_1_pl"]=> string(32) "8de3f734a5616754fea864a94c0ac34e" ["content_db_lang_su_1_pl_lc"]=> string(32) "9603fc099cd86d769b58819fcd615788" ["content_db_lang_sl_1_pl_lc"]=> string(32) "9603fc099cd86d769b58819fcd615788" ["sort_field_1"]=> string(32) "1f7a40a0196146c769a48f490ab01cc6" ["sort_field_2"]=> string(32) "ee5872f83a815355414cbb9bce87da55" } ["originalWords"]=> array(0) { } ["_initialized":protected]=> bool(true) ["_childrenResults":protected]=> array(0) { } ["_permissions":protected]=> NULL ["_originalPermissions":protected]=> NULL ["noCopyButton"]=> bool(false) ["contentPostedIn":protected]=> array(0) { } ["_followData"]=> NULL ["queued":protected]=> NULL ["_data":protected]=> array(8) { ["id"]=> int(1) ["short"]=> string(11) "en_GB.UTF-8" ["title"]=> string(7) "English" ["default"]=> int(1) ["isrtl"]=> int(0) ["protected"]=> int(1) ["order"]=> int(1) ["enabled"]=> int(1) } ["_new":protected]=> bool(false) ["changed"]=> array(0) { } ["skipCloneDuplication"]=> bool(false) } ["_url":protected]=> NULL ["profileFields"]=> NULL ["_reputationData":protected]=> NULL ["_reputationLastDayWon":protected]=> NULL ["_reputationDaysWonCount":protected]=> NULL ["_following":protected]=> array(0) { } ["reportCount":protected]=> NULL ["ignorePreferences":protected]=> NULL ["_ppdLimit":protected]=> NULL ["_data":protected]=> array(15) { ["member_group_id"]=> int(2) ["mgroup_others"]=> string(0) "" ["joined"]=> int(1493282863) ["ip_address"]=> string(13) "xxx.16.69.xxx" ["timezone"]=> string(3) "UTC" ["allow_admin_mails"]=> int(1) ["pp_photo_type"]=> string(0) "" ["member_posts"]=> int(0) ["pp_main_photo"]=> NULL ["pp_thumb_photo"]=> NULL ["failed_logins"]=> NULL ["mfa_details"]=> NULL ["pp_reputation_points"]=> int(0) ["signature"]=> string(0) "" ["auto_track"]=> string(47) "{"content":0,"comments":0,"method":"immediate"}" } ["_new":protected]=> bool(true) ["changed"]=> array(8) { ["member_group_id"]=> int(2) ["mgroup_others"]=> string(0) "" ["joined"]=> int(1493282863) ["ip_address"]=> string(13) "185.16.69.208" ["timezone"]=> string(3) "UTC" ["allow_admin_mails"]=> int(1) ["pp_photo_type"]=> string(0) "" ["member_posts"]=> int(0) } ["skipCloneDuplication"]=> bool(false) } 

 

Posted

Thanks @Alexis C - I'm not sure why that is because I am actually logged in as admin - i've just double checked that too to make sure.

I'm not sure why that is  being shown.  Any ideas?

Thanks again.

I have tried this now in a couple of different browsers and with different users logged in and I am getting the same result in each. 

Posted

Ok, solved the issue - a stupid mistake!

My IPB is installed with www. subdomain but I was running the script without www. so I'm guessing the cookies weren't being read.

Thank you both very much for all your help, sorry for wasting your time!

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...