diff --git a/admin.php b/admin.php
index 119ce98a9..7aa13dfe9 100644
--- a/admin.php
+++ b/admin.php
@@ -11,7 +11,7 @@
if ( isset ( $_COOKIE['webcalendar_csscache'] ) )
$webcalendar_csscache += $_COOKIE['webcalendar_csscache'];
-SetCookie ( 'webcalendar_csscache', $webcalendar_csscache );
+sendCookie ( 'webcalendar_csscache', $webcalendar_csscache );
function save_pref ( $prefs, $src ) {
global $error;
diff --git a/includes/classes/WebCalendar.php b/includes/classes/WebCalendar.php
index 6b2cc0005..6e7de1d21 100644
--- a/includes/classes/WebCalendar.php
+++ b/includes/classes/WebCalendar.php
@@ -569,7 +569,7 @@ function _initValidate() {
if ( ! empty ( $login ) && $login != addslashes ( $login ) ) {
// The following deletes the bad cookie.
// So, the user just needs to reload.
- SetCookie ( 'webcalendar_session', '', 0 );
+ sendCookie ( 'webcalendar_session', '', 0 );
die_miserable_death ( 'Illegal characters in login '
. htmlentities ( $login )
. '. Press browser reload to clear bad cookie.' );
diff --git a/includes/common_admin_pref.php b/includes/common_admin_pref.php
index 5574533e8..6f0f2a306 100755
--- a/includes/common_admin_pref.php
+++ b/includes/common_admin_pref.php
@@ -7,7 +7,7 @@
if ( isset ( $_COOKIE['webcalendar_csscache'] ) )
$webcalendar_csscache += $_COOKIE['webcalendar_csscache'];
-SetCookie ( 'webcalendar_csscache', $webcalendar_csscache );
+sendCookie ( 'webcalendar_csscache', $webcalendar_csscache );
$catStr = $color_sets = $currenttab = $datestyle_md = $datestyle_my = '';
$datestyle_tk = $datestyle_ymd = $lang_list = $menu_theme_list = '';
@@ -333,4 +333,4 @@ function save_pref ( $prefs, $src ) {
load_user_preferences ();
}
-?>
\ No newline at end of file
+?>
diff --git a/includes/functions.php b/includes/functions.php
index 4035dc968..580d6f269 100644
--- a/includes/functions.php
+++ b/includes/functions.php
@@ -2624,7 +2624,7 @@ function get_last_view ( $clear=true ) {
? str_replace ( '&', '&', $_COOKIE['webcalendar_last_view'] ) : '' );
if ( $clear )
- SetCookie ( 'webcalendar_last_view', '', 0 );
+ sendCookie ( 'webcalendar_last_view', '', 0 );
return $val;
}
@@ -5600,7 +5600,7 @@ function remember_this_view ( $view = false ) {
if ( strstr ( $REQUEST_URI, 'friendly=' ) )
return;
- SetCookie ( 'webcalendar_last_view', $REQUEST_URI );
+ sendCookie ( 'webcalendar_last_view', $REQUEST_URI );
}
@@ -6520,4 +6520,21 @@ function require_valid_referring_url ()
}
}
+/**
+ * Is the current connection using HTTPS rather than HTTP?
+ */
+function isSecure() {
+ return
+ (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off')
+ || $_SERVER['SERVER_PORT'] == 443;
+}
+
+function sendCookie($name, $value, $expiration=0, $sensitive=true) {
+ $path = '';
+ $domain = '';
+ // If sensitive and HTTPS is supported, set secure to true
+ $secure = $sensitive && isSecure();
+ SetCookie ( $name, $value, $expiration, $path, $domain, $secure, false);
+}
+
?>
diff --git a/includes/init.php b/includes/init.php
index d7440b938..3b9552fd5 100644
--- a/includes/init.php
+++ b/includes/init.php
@@ -236,7 +236,7 @@ function print_header( $includes = '', $HeadX = '', $BodyX = '',
$webcalendar_csscache = $_COOKIE['webcalendar_csscache'];
else {
$webcalendar_csscache = 1;
- SetCookie( 'webcalendar_csscache', $webcalendar_csscache );
+ sendCookie( 'webcalendar_csscache', $webcalendar_csscache );
}
$ret .= '