Advanced search  

News:

CPG Release 1.6.26
Correct PHP8.2 issues with user and language managers.
Additional fixes for PHP 8.2
Correct PHP8 error with SMF 2.0 bridge.
Correct IPTC supplimental category parsing.
Download and info HERE

Pages: [1]   Go Down

Author Topic: detecting succesfull coppermine logins  (Read 5008 times)

0 Members and 1 Guest are viewing this topic.

johnm1019

  • Coppermine newbie
  • Offline Offline
  • Posts: 9
detecting succesfull coppermine logins
« on: July 18, 2007, 08:20:32 pm »

I'm creating a custom site, and I am using coppermine for its photo abilities.  Because of this, I am going to use coppermine as a user/login manager.
How can I hook into the cookies or whatever after a user has logged in via coppermine to know in my application that a user is successfully logged in and grab their username?

The site is hosted as mydomain.com/app and the gallery is gallery.mydomain.com -- the two sites are also using the same database, as I dig through other parts of the coppermine database for photo stuff, so if I need to check a hash against the session table or something I can do that.


How do I do this?  What do I do with which cookies?
Logged

Nibbler

  • Guest
Re: detecting succesfull coppermine logins
« Reply #1 on: July 18, 2007, 08:28:30 pm »

Generate the client_id, like so

Code: [Select]
                $this->client_id = md5($_SERVER['HTTP_USER_AGENT'].$_SERVER['SERVER_PROTOCOL'].$CONFIG['site_url']);

That is just an md5 hash of the user agent, protocol and site url.

That client_id is the name of the cookie you need to look for. When you read that cookie you get the sessioncookie.

Code: [Select]
                // Get the session cookie value
                $sessioncookie = $_COOKIE[$this->client_id];

Use that to generate the session_id using the client_id you had from before

Code: [Select]
                // Create the session id by concat(session_cookie_value, client_id)
                $session_id = $sessioncookie.$this->client_id;

The session_id stored in the sessions table is an md5 hash of the session_id you just calculated, so you can look that up and get the user_id from it.

Code: [Select]
                    // Check for valid session
                    $sql =  'select user_id from '.$this->sessionstable.' where session_id=md5("'.$session_id.'");';
                    $result = cpg_db_query($sql);

All code from bridge/coppermine.inc.php
Logged

johnm1019

  • Coppermine newbie
  • Offline Offline
  • Posts: 9
Re: detecting succesfull coppermine logins
« Reply #2 on: July 18, 2007, 09:29:52 pm »

Thank you!
You might sticky this because if you try and search for it, all your results are inundated with people looking to bridge coppermine to open-source platform xyz, rarely the other way around :).
Logged

johnm1019

  • Coppermine newbie
  • Offline Offline
  • Posts: 9
Re: detecting succesfull coppermine logins
« Reply #3 on: July 23, 2007, 04:54:18 pm »

For those who find this later a little more info for ya.

I have my site setup as subdomain1.whatever.com and subdomain2.whatever.com (one of those is for the gallery, the other for the application)

By default coppermine specifies no domain for the cookie so the default is used which is the complete gallery.mydomain.com
If you want the cookies to be readable across all subdomains, go into bridge/coppermine.inc.php and find the only line that has "setcookie" on it.

What is there is
setcookie( $this->client_id, $this->session_id, time() + (CPG_WEEK*2), $CONFIG['cookie_path'] );

change that to
setcookie( $this->client_id, $this->session_id, time() + (CPG_WEEK*2), '/', '.yourdomain.com' );

The default cookie path is / anyway IIRC but why take risks.

Now your app on app.yourdomain.com can read the cookie that was set by the gallery at gallery.yourdomain.com
Logged

Joachim Müller

  • Dev Team member
  • Coppermine addict
  • ****
  • Offline Offline
  • Gender: Male
  • Posts: 47843
  • aka "GauGau"
    • gaugau.de
Re: detecting succesfull coppermine logins
« Reply #4 on: July 24, 2007, 08:58:49 am »

The default cookie path is / anyway IIRC but why take risks.
There is only a risk if you don't own the domain, but are on a subdomain (like yoursubdomain.yourfreehost.tld). If the domain is yours, there is no risk and you should not mess with the cookie path.
Logged
Pages: [1]   Go Up
 

Page created in 0.019 seconds with 19 queries.