Help - Search - Members - Calendar
Full Version: Possible to export forum member name to script?
Invision Power Services > Community Forums > Community Web Design and Coding
GeeZuZz
I'm creating a simple php web page that is supposed to only be available for my forum members. Are there any way i can have this script get the member name of the member that access it?

Isn't this info stored in cookies or something like that, so my script can read the user's cookie?
Frankl.in
If it is called within the IPB framework you can find all details of the current member in $ipsclass->member which is an array, so to get the member's name you can use $ipsclass->member['name']

If all you have is a cookie, you can use the cookie variable 'forumsession_id' and search the field 'id' in the ipb_sessions table in your forum's database. When you've found a match, you find the member's name in the field 'member_name'.
ellawella
Or, if they are logged in, their member ID will be accessible through $_COOKIE['member_id'].
Arts&Faith
Can someone give a complete example of a "hello world" page that does this? I'm a tinkerer, not a developer, so I don't understand some of the calls behind cookie-handling in PHP, for example.
ellawella
CODE
mysql_connect ('localhost', 'username', 'password');
mysql_select_db ('db');

if (isset($_COOKIE['member_id'])) {
$result = mysql_query ("SELECT members_display_name FROM ibf_members WHERE id=".intval($_COOKIE['member_id']));

$row = mysql_fetch_array($result);

echo "Your name is ".$row['members_display_name'];

} else {

echo "You aren't logged in";

}


Or something.
Antony
You can use the IPB API - its much easier and allows you to access other IPB functions.

CODE
// Load the IPB API!
require_once(./forums/sources/api/api_core.php);
$ipb =& new api_core;
$ipb->api_init();

// $ipb->member is an array containing the currently logged in users info.
print ($ipb->member['id']); // Displays the members ID.
print ($ipb->member['member_display_name']); // Displays the members display name.
ellawella
Quotes required around ./forums/sources/api/api_core.php.

Besides that, way to upstage me. tongue.gif
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.