PLEASE NOTE: I haven't yet determined if this is secure or not, as I'm accessing the database directly, rather than through the phpbb3 system.
// Display CPG Images in PhpBB Profile - Written by Nic Mason - NicMason.com
// I have my Coppermine Gallery integrated with Joomla,
// so in this code I'm accessing the Joomla database to get the user IDs,
// as they are the same as the CPG user IDs and CPG usernames due to the integration.
// If you don't have CPG integrated with Joomla you'll have to check and
// likely change the database names and table names to successfully retrieve
// the user IDs from the CPG database instead.
// Remember to check ALL your database and table names
// as you may need to change the defaults I've used here.
// Santé! - NicMason.com
Enter your host and database info in this code and save it as cpgimages.php in the root of your phpBB forum installation, ie: in the same folder as the phpBB config.php file.
<?php
// Display CPG Images in PhpBB Profile - Written by Nic Mason - NicMason.com
// Please leave these comments in place when reusing or distributing this code.
// I have my Coppermine Gallery integrated with Joomla,
// so in this code I'm accessing the Joomla database to get the user IDs,
// as they are the same as the CPG user IDs and CPG usernames due to the integration.
// If you don't have CPG integrated with Joomla you'll have to check and
// likely change the database names and table names to successfully retrieve
// the user IDs from the CPG database instead.
// Remember to check ALL your database and table names
// as you may need to change the defaults I've used here.
// Santé! - NicMason.com
function curPageURL() {
$pageURL = 'http';
if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
$pageURL .= "://";
if ($_SERVER["SERVER_PORT"] != "80") {
  $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
} else {
  $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
}
return $pageURL;
}
$url = curPageURL();
$mystring = $url;
$findme   = '&u=';
$pos = strpos($mystring, $findme);
$uidpos = $pos+3;
$uid_inter = substr($mystring, $uidpos);
for($i=0; $i<strlen($uid_inter); $i++){
if(!is_numeric(substr($uid_inter, $i, 1))){
$uid = substr($uid_inter, 0, $i);
break;
}
else{
$uid = $uid_inter;
}
}
$profile_name = '';
$gallery_id = 0;
$owner_id = 0;
$username = "---------------------"; // Enter your host username,  in place of ---------------------.
$password = "---------------------"; // Enter your host password.
$hostname = "localhost"; // Enter your hostname,  usually "localhost".
$dbh = mysql_connect($hostname, $username, $password)
or die("Unable to connect to MySQL");
$selected = mysql_select_db("---------------------",$dbh) // Enter your phpBB database name.
or die("Could not select the database.");
$result = mysql_query("select username from phpbb_users WHERE user_id=$uid"); // Check YOUR phpBB database table names against these.
while ($row = mysql_fetch_row($result)) {
for ($i=0; $i<mysql_num_fields($result); $i++) {
$profile_name = "$row[$i]";
}
}
mysql_close($dbh);
$dbh = mysql_connect($hostname, $username, $password)
or die("Unable to connect to MySQL");
$selected = mysql_select_db("---------------------",$dbh)  // Enter your Joomla database name.
or die("Could not select the database.");
$result = mysql_query("select id from jos_users WHERE username='$profile_name'"); // Check YOUR Joomla database table names.
while ($row = mysql_fetch_row($result)) {
for ($i=0; $i<mysql_num_fields($result); $i++) {
$gallery_id = "$row[$i]";
}
}
/*
To help find MySQL error - Use code below...
*/
        if ($row = mysql_fetch_row($result)) {
           return $row;
        } else {
           print (mysql_error());
        }
mysql_close($dbh);
$dbh = mysql_connect($hostname, $username, $password)
or die("Unable to connect to MySQL");
$selected = mysql_select_db("---------------------",$dbh)  // Enter your CPG database name.
or die("Could not select the database.");
$result = mysql_query("select owner_id from cpg14x_pictures WHERE owner_id=$gallery_id"); // Check YOUR CPG database table names.
while ($row = mysql_fetch_row($result)) {
for ($i=0; $i<mysql_num_fields($result); $i++) {
$owner_id = "$row[$i]";
}
}
mysql_close($dbh);
$objCpm = new cpm("../gallery/cpmfetch/cpmfetch_config.php");  // Check YOUR cpmfetch path.
$objCpm->cpm_viewRandomMediaFrom("owner=$profile_name",1,9);
$objCpm->cpm_close();
// Display CPG Images in PhpBB Profile - Written by Nic Mason - NicMason.com
// Please leave these comments in place when reusing or distributing this code.  Santé!
// NicMason.com
?>
Replace the path in the following code with YOUR path to your cpmfetch.php file (from the phpBB forum root.)
Then add this code to the phpBB file memberlist.php at around line 20 (after the second "include" line.)
include "../gallery/cpmfetch/cpmfetch.php";
In your phpBB style template folder open memberlist_view.php
and find <!-- IF SIGNATURE -->
Just BEFORE this line, insert the following code:
<!-- INCLUDEPHP cpgimages.php -->
EDIT: Add the following to /forum/.htaccess which will hopefully do the trick of keeping the vital data hidden... I recommend anyone who uses this to rename "cpgimages.php" to something else, wherever it appears in the code submitted here (above and below.)
<Files "cpgimages.php">
Order Allow,Deny
Deny from All
</Files>
Enable PHP in your PhpBB Admin, and you're done!
NicMason.com
(Edit: Fixed non-essential grammatical error. - 19-02-2009)