GeeZuZz
Apr 11 2006, 09:05 PM
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
Apr 12 2006, 03:49 AM
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
Apr 12 2006, 03:05 PM
Or, if they are logged in, their member ID will be accessible through $_COOKIE['member_id'].
Arts&Faith
Apr 12 2006, 03:28 PM
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
Apr 12 2006, 05:47 PM
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
Apr 17 2006, 01:28 PM
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
Apr 17 2006, 05:59 PM
Quotes required around ./forums/sources/api/api_core.php.
Besides that, way to upstage me.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please
click here.