user_info['ip'] ...

Started by alexandervba, April 11, 2011, 12:05:45 PM

Previous topic - Next topic

alexandervba

For SMF. I have defined $starter to be a the topic starter, I am now trying to get the Name and the IP from $starter in php... I tried things like this:

$ip = $starter['ip']
$name = $starter['name']

Or do I use the $user_info?

And a lot of things like that, but I cant find it... Any idea how I can get that?

Illori

I moved this to coding discussion as this is more a coding issue then core smf issue. it was posted in 1.1.* support.

alexandervba


Matthew K.

Have you tried running a print_r() of $starter to see what's in the array?

alexandervba

yea, I know whats in there.

It depends when and where I run the script. But its allways a member ID. So I have the member Id, what I want is the member's name and the member's IP.

Arantor

$context['user']['name'] and $_SERVER['REMOTE_ADDR'] (SMF cleans this up for you)

alexandervba

If I understand SMF a little bit. Im pretty sure that $context['user']['ip'] will get me the IP of the person that excecutes the function I made. And not from the ID that I have defined as $starter

Correct me if im wrong

Matthew K.

No, you're right. Have you taken a look at the functions "loadMemberData" and "loadMemberContext"?

alexandervba

Not yet, I will google that after dinner, thx for help so far!

Matthew K.


alexandervba

thats getting a bit complicated to me...

I think I need to do something like this:

loadMemberData($starter[normal])

and then: $user_profile['ip'] ?

Btw, Ill post the code where I want to use it. Maybe Im just doing it wrong if u wanna have a look at it.

// Here we will check the accounts we validate if they have plural accounts
// Get topic starter's ip and name
$ip = $starter['ip'];      // This is wrong... Ive put my IP there to see if it works, and it does work with my IP
$name = $starter['name'];      // This is wrong too

// Try to find other members on the forum who had the same ip....
$IPmemberList = '';
$dbresult = db_query("
SELECT
ID_MEMBER, realName
FROM {$db_prefix}members
WHERE memberIP = '$ip' OR memberIP2 = '$ip'", __FILE__, __LINE__);
while($memRow = mysql_fetch_assoc($dbresult))
{
$IPmemberList .= $memRow['realName'] . "\n";
}
mysql_free_result($dbresult);

// Include any IP's that match other forum members....
$memberMatches = '';
if (!empty($IPmemberList))
{
$memberMatches = $txt['ls_matched_members'] . "\n" . $IPmemberList;

// Here we create the post in leaderboards if the approved member has plural accounts

$msgOptions = array(
'id' => 0,
'subject' => 'Multiaccount Warning: ' . $name,
'body' => 'IP: ' . $ip . '[br][br]' . $memberMatches,
'icon' => 'xx',
'smileys_enabled' => 1,
'attachments' => array(),
'description' => '',
);
$topicOptions = array(
'id' => 0,
'board' => 2.0,
'mark_as_read' => true,
);
$posterOptions = array(
'id' => 1997,
'update_post_count' => 1,
);
   
require_once($sourcedir . '/Subs-Post.php');
createPost($msgOptions, $topicOptions, $posterOptions);
}


This is just part of my function. Its a lot longer, so everything is defined ect... The only thing that is wrong are the first few lines where im trying to get the IP & name...

alexandervba

This makes me so mad lol, i was kinda happy i got all the info and it was going great, and i cant finish this small detail lol. So mad at myself ^^

Whatever I do, i just cant seem to get the IP or membername :s

Matthew K.

Use the two functions I posted above...in correspondence with $user_profile[$member['id']]['ip'] or $user_profile[$member['id']]['name'].

I have done basically this exact thing with a mod I was writing recently.

alexandervba

Meh, gonna try some more tomorrow, off to bed now.

If someone can check wether im getting close :o

global $user_profile;

                loadMemberData($starter);
loadMemberContext($starter, false, 'normal');

$ip =  $user_profile[$member['id']]['ip'];
$name = $user_profile[$member['id']]['name'];

alexandervba

not working in any way I try :s

alexandervba

Could U tell me what code u used?

Matthew K.

Try this...
global $user_profile;
loadMemberData(array($starter), false, 'normal');
loadMemberContext($starter);
$ip =  $user_profile[$member['id']]['ip'];
$name = $user_profile[$member['id']]['name'];

alexandervba

Didnt work :(

Getting these errors:

8: Undefined variable: member
File: /home/foerscom/public_html/forums/Sources/Display.php
Line: 1384

8: Undefined index:
File: /home/foerscom/public_html/forums/Sources/Display.php
Line: 1384

8: Undefined variable: member
File: /home/foerscom/public_html/forums/Sources/Display.php
Line: 1385

8: Undefined index:
File: /home/foerscom/public_html/forums/Sources/Display.php
Line: 1385

Matthew K.

Try doing a print_r() of $user_profile below the loadMemberData and loadMemberContext.
echo '<pre>', print_r($user_profile), '</pre>';
What does it return?

Arantor

-sigh-

The problem isn't the contents of $user_profile. Hence undefined variable member... $member isn't set!

Advertisement: