summaryrefslogtreecommitdiff
blob: 37773842a5c1c5a0bcece670fb8464f691b12a0b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php

if ( ! class_exists( 'WMobilePack_Cookie' ) ) {

    /**
     * Overall Cookie Management class
     *
     * Instantiates all the cookies and offers a number of utility methods to work with the cookies
     */
    class WMobilePack_Cookie
    {

        /* ----------------------------------*/
        /* Properties						 */
        /* ----------------------------------*/

        public static $prefix = 'wmp_';

        /* ----------------------------------*/
        /* Methods							 */
        /* ----------------------------------*/

        /**
         *
         * Get cookie value
         *
         * @param $cookie_name
         * @return null
         *
         */
        public function get_cookie($cookie_name)
        {

            if (isset($_COOKIE[self::$prefix.$cookie_name])){
                return $_COOKIE[self::$prefix.$cookie_name];
            }

            return null;
        }

        /**
         * Set cookie value
         *
         * @param $cookie_name
         * @param $cookie_value
         * @param $duration - After how many seconds the cookie will expire. Default value is 2 days
         */
        public function set_cookie($cookie_name, $cookie_value, $duration = 172800)
        {
            setcookie(self::$prefix.$cookie_name, $cookie_value, time()+$duration,'/');
        }

    }
}