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-2007 PhpWebGallery Team - http://phpwebgallery.net | |
---|
6 | // +-----------------------------------------------------------------------+ |
---|
7 | // | file : $Id: functions_cookie.inc.php 2010 2007-05-14 21:08:53Z rub $ |
---|
8 | // | last update : $Date: 2007-05-14 21:08:53 +0000 (Mon, 14 May 2007) $ |
---|
9 | // | last modifier : $Author: rub $ |
---|
10 | // | revision : $Revision: 2010 $ |
---|
11 | // +-----------------------------------------------------------------------+ |
---|
12 | // | This program is free software; you can redistribute it and/or modify | |
---|
13 | // | it under the terms of the GNU General Public License as published by | |
---|
14 | // | the Free Software Foundation | |
---|
15 | // | | |
---|
16 | // | This program is distributed in the hope that it will be useful, but | |
---|
17 | // | WITHOUT ANY WARRANTY; without even the implied warranty of | |
---|
18 | // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
---|
19 | // | General Public License for more details. | |
---|
20 | // | | |
---|
21 | // | You should have received a copy of the GNU General Public License | |
---|
22 | // | along with this program; if not, write to the Free Software | |
---|
23 | // | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | |
---|
24 | // | USA. | |
---|
25 | // +-----------------------------------------------------------------------+ |
---|
26 | |
---|
27 | // cookie_path returns the path to use for the PhpWebGallery cookie. |
---|
28 | // If PhpWebGallery is installed on : |
---|
29 | // http://domain.org/meeting/gallery/category.php |
---|
30 | // cookie_path will return : "/meeting/gallery" |
---|
31 | function cookie_path() |
---|
32 | { |
---|
33 | if ( isset($_SERVER['REDIRECT_SCRIPT_NAME']) and |
---|
34 | !empty($_SERVER['REDIRECT_SCRIPT_NAME']) ) |
---|
35 | { |
---|
36 | $scr = $_SERVER['REDIRECT_SCRIPT_NAME']; |
---|
37 | } |
---|
38 | else if ( isset($_SERVER['REDIRECT_URL']) ) |
---|
39 | { |
---|
40 | // mod_rewrite is activated for upper level directories. we must set the |
---|
41 | // cookie to the path shown in the browser otherwise it will be discarded. |
---|
42 | if |
---|
43 | ( |
---|
44 | isset($_SERVER['PATH_INFO']) and !empty($_SERVER['PATH_INFO']) and |
---|
45 | ($_SERVER['REDIRECT_URL'] !== $_SERVER['PATH_INFO']) and |
---|
46 | (substr($_SERVER['REDIRECT_URL'],-strlen($_SERVER['PATH_INFO'])) |
---|
47 | == $_SERVER['PATH_INFO']) |
---|
48 | ) |
---|
49 | { |
---|
50 | $scr = substr($_SERVER['REDIRECT_URL'], 0, |
---|
51 | strlen($_SERVER['REDIRECT_URL'])-strlen($_SERVER['PATH_INFO'])); |
---|
52 | } |
---|
53 | else |
---|
54 | { |
---|
55 | $scr = $_SERVER['REDIRECT_URL']; |
---|
56 | } |
---|
57 | } |
---|
58 | else |
---|
59 | { |
---|
60 | $scr = $_SERVER['SCRIPT_NAME']; |
---|
61 | } |
---|
62 | |
---|
63 | $scr = substr($scr,0,strrpos( $scr,'/')); |
---|
64 | |
---|
65 | // add a trailing '/' if needed |
---|
66 | if ((strlen($scr) == 0) or ($scr{strlen($scr)-1} !== '/')) |
---|
67 | { |
---|
68 | $scr .= '/'; |
---|
69 | } |
---|
70 | |
---|
71 | if ( substr(PHPWG_ROOT_PATH,0,3)=='../') |
---|
72 | { // this is maybe a plugin inside pwg directory |
---|
73 | // TODO - what if it is an external script outside PWG ? |
---|
74 | $scr = $scr.PHPWG_ROOT_PATH; |
---|
75 | while (1) |
---|
76 | { |
---|
77 | $new = preg_replace('#[^/]+/\.\.(/|$)#', '', $scr); |
---|
78 | if ($new==$scr) |
---|
79 | { |
---|
80 | break; |
---|
81 | } |
---|
82 | $scr=$new; |
---|
83 | } |
---|
84 | } |
---|
85 | return $scr; |
---|
86 | } |
---|
87 | |
---|
88 | /** |
---|
89 | * persistently stores a variable in pwg cookie |
---|
90 | * @return boolean true on success |
---|
91 | * @see pwg_get_cookie_var |
---|
92 | */ |
---|
93 | function pwg_set_cookie_var($var, $value) |
---|
94 | { |
---|
95 | $_COOKIE['pwg_'.$var] = $value; |
---|
96 | return |
---|
97 | setcookie('pwg_'.$var, $value, |
---|
98 | strtotime('+10 years'), cookie_path()); |
---|
99 | } |
---|
100 | |
---|
101 | /** |
---|
102 | * retrieves the value of a persistent variable in pwg cookie |
---|
103 | * @return mixed |
---|
104 | * @see pwg_set_cookie_var |
---|
105 | */ |
---|
106 | function pwg_get_cookie_var($var, $default = null) |
---|
107 | { |
---|
108 | if (isset($_COOKIE['pwg_'.$var])) |
---|
109 | { |
---|
110 | return $_COOKIE['pwg_'.$var]; |
---|
111 | } |
---|
112 | else |
---|
113 | { |
---|
114 | return $default; |
---|
115 | } |
---|
116 | } |
---|
117 | |
---|
118 | ?> |
---|