source: trunk/include/user.inc.php @ 1511

Last change on this file since 1511 was 1511, checked in by nikrou, 18 years ago

Fix bug 451: improvement
small problem with reconnexion after session timeout
add auto-login function
all staff for session (connexion, auto-login and logout)
is now in include/user.inc.php

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.8 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | PhpWebGallery - a PHP based picture gallery                           |
4// | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net |
5// | Copyright (C) 2003-2005 PhpWebGallery Team - http://phpwebgallery.net |
6// +-----------------------------------------------------------------------+
7// | branch        : BSF (Best So Far)
8// | file          : $RCSfile$
9// | last update   : $Date: 2006-07-28 09:34:27 +0000 (Fri, 28 Jul 2006) $
10// | last modifier : $Author: nikrou $
11// | revision      : $Revision: 1511 $
12// +-----------------------------------------------------------------------+
13// | This program is free software; you can redistribute it and/or modify  |
14// | it under the terms of the GNU General Public License as published by  |
15// | the Free Software Foundation                                          |
16// |                                                                       |
17// | This program is distributed in the hope that it will be useful, but   |
18// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
19// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
20// | General Public License for more details.                              |
21// |                                                                       |
22// | You should have received a copy of the GNU General Public License     |
23// | along with this program; if not, write to the Free Software           |
24// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
25// | USA.                                                                  |
26// +-----------------------------------------------------------------------+
27
28if (isset($_COOKIE[session_name()]))
29{
30  session_start();
31  if (isset($_GET['act']) and $_GET['act'] == 'logout')
32  {
33    // logout
34    $_SESSION = array();
35    session_unset();
36    session_destroy();
37    setcookie(session_name(),'',0,
38              ini_get('session.cookie_path'), 
39              ini_get('session.cookie_domain') 
40              );
41    setcookie($conf['remember_me_name'], '', 0, cookie_path());
42    redirect(make_index_url());
43  } 
44  elseif (empty($_SESSION['pwg_uid'])) 
45  {
46    // timeout
47    setcookie(session_name(),'',0,
48              ini_get('session.cookie_path'), 
49              ini_get('session.cookie_domain') 
50              );
51  }
52  else
53  {
54    $user['id'] = $_SESSION['pwg_uid'];
55    $user['is_the_guest'] = false;
56  }
57}
58elseif (!empty($_COOKIE[$conf['remember_me_name']]))
59{
60  auto_login();
61} 
62else
63{
64  $user['id'] = $conf['guest_id'];
65  $user['is_the_guest'] = true;
66}
67
68if ($user['is_the_guest'] and !$conf['guest_access'])
69{
70  redirect (get_root_url().'identification.php');
71}
72
73// using Apache authentication override the above user search
74if ($conf['apache_authentication'] and isset($_SERVER['REMOTE_USER']))
75{
76  if (!($user['id'] = get_userid($_SERVER['REMOTE_USER'])))
77  {
78    register_user($_SERVER['REMOTE_USER'], '', '');
79    $user['id'] = get_userid($_SERVER['REMOTE_USER']);
80  }
81
82  $user['is_the_guest'] = false;
83}
84
85$user = array_merge(
86  $user,
87  getuserdata(
88    $user['id'],
89    ( defined('IN_ADMIN') and IN_ADMIN ) ? false : true // use cache ?
90    )
91  );
92
93// properties of user guest are found in the configuration
94if ($user['is_the_guest'])
95{
96  $user['template'] = $conf['default_template'];
97  $user['nb_image_line'] = $conf['nb_image_line'];
98  $user['nb_line_page'] = $conf['nb_line_page'];
99  $user['language'] = $conf['default_language'];
100  $user['maxwidth'] = $conf['default_maxwidth'];
101  $user['maxheight'] = $conf['default_maxheight'];
102  $user['recent_period'] = $conf['recent_period'];
103  $user['expand'] = $conf['auto_expand'];
104  $user['show_nb_comments'] = $conf['show_nb_comments'];
105  $user['enabled_high'] = $conf['newuser_default_enabled_high'];
106}
107
108// calculation of the number of picture to display per page
109$user['nb_image_page'] = $user['nb_image_line'] * $user['nb_line_page'];
110?>
Note: See TracBrowser for help on using the repository browser.