source: trunk/include/functions_cookie.inc.php @ 1993

Last change on this file since 1993 was 1993, checked in by rub, 17 years ago

Missing svn property

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Author Date Id Revision
File size: 3.7 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-2007 PhpWebGallery Team - http://phpwebgallery.net |
6// +-----------------------------------------------------------------------+
7// | file          : $Id: functions_cookie.inc.php 1993 2007-05-01 14:02:23Z rub $
8// | last update   : $Date: 2007-05-01 14:02:23 +0000 (Tue, 01 May 2007) $
9// | last modifier : $Author: rub $
10// | revision      : $Revision: 1993 $
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"
31function 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  { // mod_rewrite is activated for upper level directories. we must set the
40    // cookie to the path shown in the browser otherwise it will be discarded.
41    if ( isset($_SERVER['PATH_INFO']) and !empty($_SERVER['PATH_INFO']) )
42    {
43      $idx = strpos( $_SERVER['REDIRECT_URL'], $_SERVER['PATH_INFO'] );
44      if ($idx !== false)
45      {
46        $scr = substr($_SERVER['REDIRECT_URL'], 0, $idx);
47      }
48      else
49      {//this should never happen
50        $scr='//';
51      }
52    }
53    else
54    {
55      $scr = $_SERVER['REDIRECT_URL'];
56    }
57  }
58  else
59  {
60    $scr = $_SERVER['SCRIPT_NAME'];
61  }
62  $scr = substr($scr,0,strrpos( $scr,'/'));
63
64  // add a trailing '/' if needed
65  $scr .= ($scr{strlen($scr)-1} == '/') ? '' : '/';
66 
67  if ( substr(PHPWG_ROOT_PATH,0,3)=='../')
68  { // this is maybe a plugin inside pwg directory
69    // TODO - what if it is an external script outside PWG ?
70    $scr = $scr.PHPWG_ROOT_PATH;
71    while (1)
72    {
73      $new = preg_replace('#[^/]+/\.\.(/|$)#', '', $scr);
74      if ($new==$scr)
75      {
76        break;
77      }
78      $scr=$new;
79    }
80  }
81  return $scr;
82}
83
84/**
85 * persistently stores a variable in pwg cookie
86 * @return boolean true on success
87 * @see pwg_get_cookie_var
88 */
89function pwg_set_cookie_var($var, $value)
90{
91  $_COOKIE['pwg_'.$var] = $value;
92  return
93    setcookie('pwg_'.$var, $value, 
94      strtotime('+10 years'), cookie_path());
95}
96
97/**
98 * retrieves the value of a persistent variable in pwg cookie
99 * @return mixed
100 * @see pwg_set_cookie_var
101 */
102function pwg_get_cookie_var($var, $default = null)
103{
104  if (isset($_COOKIE['pwg_'.$var]))
105  {
106    return $_COOKIE['pwg_'.$var];
107  }
108  else
109  {
110    return $default;
111  }
112}
113
114?>
Note: See TracBrowser for help on using the repository browser.