Code rewritings, load base config improved and many minor fixes...
[mailer.git] / 0.2.1 / inc / session.php
1 <?php\r
2 /************************************************************************\r
3  * MXChange v0.2.1                                    Start: 09/16/2004 *\r
4  * ===============                              Last change: 11/23/2004 *\r
5  *                                                                      *\r
6  * -------------------------------------------------------------------- *\r
7  * File              : session.php                                      *\r
8  * -------------------------------------------------------------------- *\r
9  * Short description : Session management                               *\r
10  * -------------------------------------------------------------------- *\r
11  * Kurzbeschreibung  : Sitzungs-Management                              *\r
12  * -------------------------------------------------------------------- *\r
13  *                                                                      *\r
14  * -------------------------------------------------------------------- *\r
15  * Copyright (c) 2003 - 2008 by Roland Haeder                           *\r
16  * For more information visit: http://www.mxchange.org                  *\r
17  *                                                                      *\r
18  * This program is free software; you can redistribute it and/or modify *\r
19  * it under the terms of the GNU General Public License as published by *\r
20  * the Free Software Foundation; either version 2 of the License, or    *\r
21  * (at your option) any later version.                                  *\r
22  *                                                                      *\r
23  * This program is distributed in the hope that it will be useful,      *\r
24  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *\r
25  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *\r
26  * GNU General Public License for more details.                         *\r
27  *                                                                      *\r
28  * You should have received a copy of the GNU General Public License    *\r
29  * along with this program; if not, write to the Free Software          *\r
30  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *\r
31  * MA  02110-1301  USA                                                  *\r
32  ************************************************************************/\r
33 \r
34 // Some security stuff...\r
35 if (ereg(basename(__FILE__), $_SERVER['PHP_SELF']))\r
36 {\r
37         $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";\r
38         require($INC);\r
39 }\r
40 \r
41 // Check if view.php nor click.php was called\r
42 // If not set variables to default\r
43 if (empty($CLICK)) $CLICK = 0;\r
44 if (empty($VIEW))  $VIEW  = 0;\r
45 \r
46 // Skip updating of cookies when viewing a banner\r
47 if (($VIEW == 1) && ($_SERVER['PHP_SELF'])) return;\r
48 \r
49 // Session management initalization\r
50 if (empty($PHPSESSID))\r
51 {\r
52         // This fixes some strange session cookie problems\r
53         if (empty($_COOKIE['PHPSESSID'])) unset($_COOKIE['PHPSESSID']);\r
54         @session_start();\r
55         $PHPSESSID = @session_id();\r
56 }\r
57  else\r
58 {\r
59         @session_id($PHPSESSID);\r
60         @session_start();\r
61 }\r
62 \r
63 // Store PHPSESSID\r
64 @setcookie("PHPSESSID", $PHPSESSID, (time() + $CONFIG['online_timeout']), COOKIE_PATH);\r
65 \r
66 // Store language code in cookie\r
67 @setcookie("mx_lang", $mx_lang, (time() + $CONFIG['online_timeout']), COOKIE_PATH);\r
68 \r
69 // Check if refid is set\r
70 if ((!empty($_GET['user'])) && ($CLICK == 1) && ($_SERVER['PHP_SELF'] == "click.php")) {\r
71         // The variable user comes from the click-counter script click.php and we only accept this here\r
72         $GLOBALS['refid'] = bigintval($_GET['user']);\r
73 }\r
74 \r
75 if (!empty($_POST['refid'])) {\r
76         // Get referral id from variable refid (so I hope this makes my script more compatible to other scripts)\r
77         $GLOBALS['refid'] = SQL_ESCAPE(strip_tags($_POST['refid']));\r
78 } elseif (!empty($_GET['refid'])) {\r
79         // Get referral id from variable refid (so I hope this makes my script more compatible to other scripts)\r
80         $GLOBALS['refid'] = SQL_ESCAPE(strip_tags($_GET['refid']));\r
81 } elseif (!empty($_GET['ref'])) {\r
82         // Set refid=ref (the referral link uses such variable)\r
83         $GLOBALS['refid'] = SQL_ESCAPE(strip_tags($_GET['ref']));\r
84 } elseif (!empty($_COOKIE['refid'])) {\r
85         // Simply reset cookie\r
86         $GLOBALS['refid'] = bigintval($_COOKIE['refid']);\r
87 } elseif (GET_EXT_VERSION("sql_patches") != "") {\r
88         // Set default refid as refid in URL\r
89         $GLOBALS['refid'] = $CONFIG['def_refid'];\r
90 } else {\r
91         // No default ID when sql_patches is not installed\r
92         $GLOBALS['refid'] = 0;\r
93 }\r
94 \r
95 // Set cookie when default refid > 0\r
96 if (empty($_COOKIE['refid']) || (!empty($GLOBALS['refid'])) || (($_COOKIE['refid'] == "0") && ($CONFIG['def_refid'] > 0))) {\r
97         // Set cookie\r
98         @setcookie("refid", $GLOBALS['refid'], (time() + $CONFIG['online_timeout']), COOKIE_PATH);\r
99 }\r
100 \r
101 // Test cookies if index.php or modules.php is loaded\r
102 if ((basename($_SERVER['PHP_SELF']) == "index.php") || (basename($_SERVER['PHP_SELF']) == "modules.php") || (mxchange_installing))\r
103 {\r
104         if (count($_COOKIE) > 0)\r
105         {\r
106                 // Cookies accepted!\r
107                 define('__COOKIES', true);\r
108         }\r
109          else\r
110         {\r
111                 // Cookies rejected!\r
112                 define('__COOKIES', false);\r
113         }\r
114 }\r
115 //\r
116 ?>\r