Using USER_ID Using USER_ID
 

News:

cpg1.5.48 Security release - upgrade mandatory!
The Coppermine development team is releasing a security update for Coppermine in order to counter a recently discovered vulnerability. It is important that all users who run version cpg1.5.46 or older update to this latest version as soon as possible.
[more]

Main Menu

Using USER_ID

Started by nickfzx, May 27, 2006, 01:37:25 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

nickfzx

So I have coppermine bridged with punbb.  I want to have a login box at the top so I wrote one into theme.php but I am having a problem with the loginbox not being able to fetch user data from the shared cookie...i think it is because 'global $pun_user' is being defined from within a function and therefore is not global (scope issue).  I posted my problem in more specifics on the punbb forums and this is the most useful reply I got:

"If you're bridged then it would be easier to use Coppermine's login constant USER_ID. If that is 0 then the user is not logged in, otherwise it has the punbb userid."

So here is the code of my theme.php file at the moment:

<?php
/********************************************
  Coppermine version: 1.4.5
  $Source: /cvsroot/coppermine/stable/themes/classic/theme.php,v $
  $Revision: 1.16 $
  $Author: gaugau $
  $Date: 2006/03/02 08:25:15 $
**********************************************/
// ------------------------------------------------------------------------- //
// This theme has all CORE items removed                                     //
// ------------------------------------------------------------------------- //
define('THEME_IS_XHTML10_TRANSITIONAL',1);

function 
pageheader($section$meta '')
{
   global 
$CONFIG$THEME_DIR;
   global 
$template_header$lang_charset$lang_text_dir;

   if(empty(
$custom_header)){
  
define('PUN_ROOT''path to punbb root directory/');


global 
$db;
global 
$pun_user;
 
include 
'path to punbb forum/include/common.php';

if (
$pun_user['is_guest']) {

//if the user is a guest then stick down a login box
echo '<a>Username  &  Password</a>';
  echo 
"<form id=\"login\" method=\"post\" action=\"/pun/login.php?action=in\" onsubmit=\"return process_form(this)\">
<input type=\"hidden\" name=\"form_sent\" value=\"1\" />
<input type=\"hidden\" name=\"redirect_url\" value=\""
.$_SERVER['SCRIPT_NAME']."\" />
<input type=\"text\" name=\"req_username\" size=\"25\" maxlength=\"25\" />
<input type=\"password\" name=\"req_password\" size=\"16\" maxlength=\"16\" />
<input type=\"submit\" name=\"login\" value=\"Login\" />
</form>"
;

echo 
'<a href="/pun/register.php">Want an account?</a>';
echo 
'<a>                    </a>';echo '<a>         or          </a>';echo '<a>                   </a>';
echo 
'<a href="/pun/login.php?action=forget">Forgot your password?</a>';
}

//    else say that the user is logged in as 'pun_user'
else {
echo 
"Logged in as: ".pun_htmlspecialchars($pun_user['username'])."
<br>Click <a href=\"/pun/login.php?action=out&id="
.$pun_user['id']."&location_out=".$_SERVER['SCRIPT_NAME']."\">here</a> to log out.</div>";
}

    static 
$custom_header;
       
$custom_header ob_get_contents();
     
ob_clean();
   }

   
header('P3P: CP="CAO DSP COR CURa ADMa DEVa OUR IND PHY ONL UNI COM NAV INT DEM PRE"');
   
user_save_profile();

   
$template_vars = array(
      
'{LANG_DIR}' => $lang_text_dir,
      
'{TITLE}' => $CONFIG['gallery_name'].' - '.$section,
      
'{CHARSET}' => $CONFIG['charset'] == 'language file' $lang_charset $CONFIG['charset'],
      
'{META}' => $meta,
      
'{GAL_NAME}' => $CONFIG['gallery_name'],
      
'{GAL_DESCRIPTION}' => $CONFIG['gallery_description'],
      
'{MAIN_MENU}' => theme_main_menu(),
      
'{ADMIN_MENU}' => theme_admin_mode_menu(),
      
'{CUSTOM_HEADER}' => $custom_header,
   );

   echo 
template_eval($template_header$template_vars);
}


// below here is all standard theme.php stuff that I have not altered




I have no knowledge of how to use coppermines USER_ID constant.  How should change this code so that it is using USER_ID?

ANy help would be greatly apreciated.

Cheers

Nick

Stramm

try instead of
if ($pun_user['is_guest']) {

if (!USER_ID) {

you can USER_NAME too (for your else clause)

nickfzx

cool thanks I'll give this a try later....do I need to define or include anything? for this to work (like I do with PUNBB) or will it just work?

Stramm

it's a constant... no need to include anything for that to work

nickfzx

Hi its working great thanks.....just can't figure out the USER_NAME use.  Just syntax I think.

here is the code of my else statement:
//    else say that the user is logged in as 'pun_user'
else {
echo "Logged in as: (USER_NAME)
<br>Click <a href=\"/pun/login.php?action=out&id=(USER_NAME)&location_out=".$_SERVER['SCRIPT_NAME']."\">here</a> to log out.</div>";
}


I've tried using [] or {} or ''

none seem to work.

Cheers
Nick

The user_id works great though

Joachim Müller

It's a constant, as suggested above. Correct syntax would be//    else say that the user is logged in as 'pun_user'
else {
    echo 'Logged in as: ';
    echo USER_NAME;
    echo '<br />Click <a href="/pun/login.php?action=out&id='.USER_NAME.'&amp;location_out='.$_SERVER['SCRIPT_NAME'].'">here</a> to log out.</div>';
}

nickfzx

Thanks guys all working now :)