comparison msite.inc.php @ 7:d76020022881

Various fixes, cleanups and improvements.
author Matti Hamalainen <ccr@tnsp.org>
date Wed, 05 Dec 2012 09:35:30 +0200
parents 76c3b89d7b11
children 4c5f651aa107
comparison
equal deleted inserted replaced
6:2a9267ad0ceb 7:d76020022881
28 28
29 29
30 function stSessionExpire($type) 30 function stSessionExpire($type)
31 { 31 {
32 // Check for session expiration 32 // Check for session expiration
33 if (!isset($_SESSION["expires"]) || $_SESSION["expires"] < time()) 33 if (!isset($_SESSION["expires"]))
34 return FALSE; 34 {
35 if (stGetSetting("debug")) error_log("Session $type expires due to expire time not set.");
36 return FALSE;
37 }
38
39 if ($_SESSION["expires"] < time())
40 {
41 if (stGetSetting("debug")) error_log("Session $type / ".session_id()." expires due to timeout ".$_SESSION["expires"]." < ".time());
42 return FALSE;
43 }
35 44
36 // Add more time to expiration 45 // Add more time to expiration
46 if (stGetSetting("debug")) error_log("Adding more time to $type session ".session_id()." :: ".stGetSetting($type));
37 $_SESSION["expires"] = time() + stGetSetting($type); 47 $_SESSION["expires"] = time() + stGetSetting($type);
38 return TRUE; 48 return TRUE;
39 } 49 }
40 50
41 51
42 function stAdmSessionAuth()
43 {
44 if (@session_start() === TRUE && isset($_SESSION["admPassword"]) &&
45 $_SESSION["admPassword"] == stGetSetting("admPassword"))
46 return stSessionExpire("admTimeout");
47 else
48 return FALSE;
49 }
50
51
52 function stAdmSessionStart()
53 {
54 if (@session_start() === TRUE)
55 {
56 $_SESSION["admPassword"] = stGetSetting("admPassword");
57 $_SESSION["expires"] = time() + stGetSetting("admTimeout");
58 return TRUE;
59 }
60 else
61 return FALSE;
62 }
63
64
65 function stVoteSessionAuth()
66 {
67 if (@session_start() === TRUE && isset($_SESSION["key"]) && isset($_SESSION["votes"]))
68 return stSessionExpire("voteTimeout");
69 else
70 return FALSE;
71 }
72
73
74 function stVoteSessionStart()
75 {
76 if (@session_start() === TRUE)
77 {
78 $_SESSION["expires"] = time() + stGetSetting("voteTimeout");
79 return TRUE;
80 }
81 else
82 return FALSE;
83 }
84
85
86 function stSetVoteStatus($st)
87 {
88 $_SESSION["status"] = $st;
89 }
90
91
92 function stSessionEnd($ok) 52 function stSessionEnd($ok)
93 { 53 {
54 if (stGetSetting("debug")) error_log("END session ".$_SESSION["type"]." / ".$_SESSION["expires"]." == ".$ok);
94 $_SESSION = array(); 55 $_SESSION = array();
95 if (ini_get("session.use_cookies")) 56 if (ini_get("session.use_cookies"))
96 { 57 {
97 $params = session_get_cookie_params(); 58 $params = session_get_cookie_params();
98 setcookie(session_name(), "", time() - 242000, 59 setcookie(session_name(), "", time() - 242000,
100 $params["secure"], $params["httponly"] 61 $params["secure"], $params["httponly"]
101 ); 62 );
102 } 63 }
103 @session_destroy(); 64 @session_destroy();
104 return $ok; 65 return $ok;
66 }
67
68
69 function stAdmSessionAuth()
70 {
71 if (@session_start() === TRUE && isset($_SESSION["admPassword"]) &&
72 $_SESSION["admPassword"] == stGetSetting("admPassword"))
73 {
74 if (stGetSetting("debug")) error_log("AUTH admin session.");
75 return stSessionExpire("admTimeout");
76 }
77 else
78 return FALSE;
79 }
80
81
82 function stAdmSessionStart()
83 {
84 if (@session_start() === TRUE)
85 {
86 if (stGetSetting("debug")) error_log("START admin session OK.");
87 $_SESSION["type"] = "admin";
88 $_SESSION["admPassword"] = stGetSetting("admPassword");
89 $_SESSION["expires"] = time() + stGetSetting("admTimeout");
90 return TRUE;
91 }
92 else
93 {
94 if (stGetSetting("debug")) error_log("START admin session --FAILED--");
95 return FALSE;
96 }
97 }
98
99
100 function stVoteSessionAuth()
101 {
102 if (@session_start() === TRUE && isset($_SESSION["key"]) && isset($_SESSION["votes"]))
103 return stSessionExpire("voteTimeout");
104 else
105 return FALSE;
106 }
107
108
109 function stVoteSessionStart()
110 {
111 if (@session_start() === TRUE)
112 {
113 $_SESSION["type"] = "vote";
114 $_SESSION["expires"] = time() + stGetSetting("voteTimeout");
115 return TRUE;
116 }
117 else
118 return FALSE;
119 }
120
121
122 function stSetVoteStatus($st)
123 {
124 $_SESSION["status"] = $st;
105 } 125 }
106 126
107 127
108 function stGetSetting($name) 128 function stGetSetting($name)
109 { 129 {