Pull user data from EE on non-EE page
Posted: 19 November 2008 04:30 PM   [ Ignore ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  517
Joined  07-08-2008

I’m trying to load in some EE user data onto a non-EE page.  I know I can do this with straight PHP/MySQL if I have the username, but I’m wondering if there is a more built-in way.

I’m using aMember for a site and use their member page as my member area.  I’m trying to pull in the current logged in member’s Group info (along with possibly other info).  Since I’m not longer in EE, instead in aMember, I can’t use EE tags.

Has anyone been able to do this in a simple manner?  Even if not with aMember, any advice would be fine.

Thanks

 Signature 

.
// INTERACTIVEDEVELOPER
Phire Branding Company

Profile
 
 
Posted: 21 November 2008 03:05 PM   [ Ignore ]   [ # 1 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  517
Joined  07-08-2008

Figured out a way to do this, but you need to be careful lest someone exploits pages that are like this.

I started off by using cURL to pull up a page from my server as though a webbrowser was pulling it in. This allowed for EE to parse the page before I captured it into my page:

$user = $this->get_template_vars('user');
session_start();
$strCookie = 'PHPSESSID=' . $_COOKIE['PHPSESSID'] . '; path=/';
session_write_close();
$curl_handle = curl_init('the_page_you_are_pointing_to'.$user['login']);
curl_setopt( $curl_handle, CURLOPT_COOKIE, $strCookie );
curl_exec($curl_handle);
curl_close($curl_handle);

Alright I just left some of my code in there that is unique to my situation.  I needed to pass some cookie info (for my own personal use) so you can ignore that portion.  What is important is the URL that I replaced with ‘the_page_you_are_pointing_to’.  This would be your EE page’s URL and if you’ll notice I appended to the end of it the username of the person.  Since I was using aMember in this, the example above is to use aMember’s login name since it matches EE’s login name.

On my EE page, I put this code:

<?
    $membername
= "{segment_3}";
    global
$DB;
    
$sql = "SELECT `member_id` FROM `exp_members` WHERE `username` = '$membername'";

    
$query = $DB->query($sql);
    foreach(
$query->result as $row)
        
$memberid = $row['member_id'];
    
?>
{exp
:member:custom_profile_data member_id="<?=$memberid?>"}
{username}
{
/exp:member:custom_profile_data}

Now you might say this is pointless since I’m writing the username from EE when I passed in a username in the first place, but it is to illustrate that this works.  The username EE spits back should be the same one you gave it, but it actually verified that username.  You can use any member profile fields not just {username}.

So the basic summary is I took the username in {segment_3} (it was in my URL) and then I did a lookup in SQL to find it within the EE database.  Once I found it, I got the member ID number that is associated with the name.

With the ID number, I simply ran the EE custom_profile_data tag and put in the member ID.  This allows me to now be able to fetch ALL the info about this member directly from EE in simple EE tags.

You can do so much with this example.  If you wanted, you could technically even have this one page give you only the username, only the member group, only the first name, or whatever else.  You just need to use conditional statements and make use of the Segement ability of EE URLs.

Anyway, the usages of this are infinite and I think this is really cool.  Hopefully it will help someone or spark some imagination.

P.S. This can be exploited so you need to be very careful.  If someone just calls this URL and puts in a valid username, they could potentially get all the information about that user (if you have it displaying from this page).  I would suggest more security such as passing in PHP Session information to verify the person is really logged in.  I did this in my version of the first block of CURL code but not in the second block of code.

 Signature 

.
// INTERACTIVEDEVELOPER
Phire Branding Company

Profile
 
 
   
 
 
Post Marker Legend
New Topic New posts Hot Topic Hot Topic with new posts New Poll New Poll Moved Topic Moved Topic Sticky Topic Sticky topic
Old Topic No new posts Hot Old Topic Hot Topic with no new posts Old Poll Old Poll Closed Topic Closed Topic Announcement Announcements
Theme
Change Theme
Visitor Statistics
The most visitors ever was 1743, on December 02, 2009 03:47 PM
Total Registered Members: 120482 Total Logged-in Users: 48
Total Topics: 126555 Total Anonymous Users: 14
Total Replies: 665407 Total Guests: 282
Total Posts: 791962    
Members ( View Memberlist )