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