pMachine: Retrieve Current Member Info

Sometimes it is useful to be able to retrieve information from the currently logged-in member’s profile in rasberryMachine:.  This could be used for something as simple as displaying the user’s “Screen Name” to a situation where you might use the information as input data in a new function.  In the standard pMachine distribution there is no simple way to do this.

Here is a simple function add-on that you can use to retrieve this data.

"Installing” and using this add-on should be simple:

1. Create a new file in your pm/scripts/ directory. Call it something like “member_info.php”.

2. Paste this code into the file. Make sure there’s no space at the end after the closing ”?>”:

<?php

function current_member_field($field="", $type="") {

// If you're running a PHP version prior to v4.1 then you'll need
// to edit these lines and replace "$_COOKIE" with
// "$HTTP_COOKIE_VARS"
global $db_members;

$member_code = $_COOKIE['member_code'];
$member_name = $_COOKIE['member_name'];

// If the field isn't set, the function fails
if ($field == "") return false;

// If the current member has the cookies set then
// query the member table for the specified field
if ( isset($member_name) && isset($member_code) ) {
$db = new DB();
$query = new DB_query($db, "SELECT $field FROM $db_members WHERE username = '$member_name'");
$query->db_fetch_object();
$field_data = $query->obj->$field;
}

// If the cookies aren't set then the function fails
else {
return false;
}

// Data can either be 'return'ed or 'echo'ed
// If $type is set to "0" (zero) the data will be returned so that it can
// be used in other PHP functions
// If $type is set to "1" or not specified the data will be echoed to the
// browser.  This is usually the expected behavior
if ($type == "0") {
return $field_data;
}
else {
echo $field_data;
}

}

?>

3. To use the new tag, simply do so like this:

<?php current_member_field("fieldnamegoeshere", 1); ?>

Parameters

There are two parameters available in the function.

Field: The first parameter is required and is the name of the field for which you want to retrieve the information.  Any of the fields in the “pm_members” table are available for use.

Common fields you might want use use include: username, signature, email, location, url, occupation, interests, bio, icq, aol_im, yahoo_im, msn_im, numentries, and numcomments.  This is not an exhaustive list of the possible values.

Type: This second parameter is optional.  If you leave this parameter blank (or use a “1") then the function will simply echo the data to the screen, similar to most pMachine functions.  This is the functionality most people will expect.

If you place a zero ("0") as the second parameter, the function will return the data instead of echo it.  This is useful if you want to assign the data to a PHP variable or use it inside a PHP function.

This is an older entry and as such, it may be by a guest author or contain formatting problems / extraneous code. If you notice something wrong with the entry, please use the Contact page to let me know the entry title and issue.

Comments

So this can be used to redisplay someones info? Say, i put my name and e-mail addy on here, and you could have it autosave my info with this and add it to a list of contacts for yourself or did i miss understand the working of this?

How much does pMachine cosdt to use monthly, and what kind of programming knowledge does it take to integrate it?

This is basically an add-on Tag for use with pMachine.  It’s useful for sites that require registration/membership to use (mine/this one doesn’t).  Let’s assume that I changed this site and required you to register an account in order to post comments.  If that were done then I could use this new add-on to be able to display a message such as “Welcome back, Greg!” when you visited.

How much does pMachine cosdt to use monthly, and what kind of programming knowledge does it take to integrate it?

pMachine Free is, well, Free.  pMachine Pro, which has extra features such as multiple weblog support (I use that here: the gallery and movie databases are separate weblogs) costs $45.  It requires that you run the program on a server with PHP and MySQL support.

As far as what knowledge you need, that’s a difficult question to answer.  It depends on what you want to do.  You can run the default/sample weblog without really having much knowledge at all, though basic HTML knowledge is useful.  For advanced sites then advanced HTML/CSS and PHP knowledge is useful.

Ive used a ,php extention on mr error page becuase i thought i had to, but i suppose i might not have had to, i just used xhtml with tables… whats the difference between php and html? like entire coding langauge? or different commmands?

PHP is a programming language, like C, BASIC, Pascal, etc.  It’s only useful if the web server is running the PHP parser.  That is, the software that understands that a .php file has code in it that it needs to process.

.js is javascript (scripting language, not a real programming language)
.asp is Cold Fusion
.php is PHP
and
.cgi is Perl

If you aren’t using PHP code, and there’s no PHP parser on the server, then that extension means nussing.

AAAAhhh ok. WEll not even havingt a decent grasp of html yet.... i dont think ill journey into the land of php., and certainly not java…

Ive got cold fusion.. is it worth its weight in anything?

No no no, you’re missing the point.

a) the server has to run the technology you wish to use.

b) pMachine requires ZERO knowledge of PHP, it’s just the platform that it was created on.

nah, i was saying i wouldnt journy into the land of coding php or java.

pMachine is intriguing though. Im starting school tommorow and sometime this week, im going to come up with a plan for a new version of my website.

this makes me wonder… when starting a sentance with a product that has a lowercase letter on purpose… do you capitalize it? or aviod using it first thing? as in

iPods have us all excited about digital media.

ugh ^ capital T in “this” and sentence is spelled like so.

Never capitalize a lowercase letter in a tradename.  Even if it starts the sentence.

I installed this hack and it works beautifully!  Thanks for sharing.

Not quite on topic, but I couldn’t figure out where else to put this.  I’m desperately trying to find a working script to use to retrieve and display recent comments on a pMachine site.  I’m at the point where if I cant get this feature working I’m going to switch to WordPress, which would be a big pain in the ass.  Can you by any chance help me out?

Dave

Leave Your Comment

Comments may be edited for content or deleted at any time. Civilized discussion is welcome. Anyone spamming, going way off topic, or otherwise being a jerk will probably be deleted or banned.

User Information

pMcode is allowed for comment formatting. pop-up mini reference

Personalization Options

Comment Security