Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
  • IPS Customization.

    While building this website I have learned a lot about how to customiza different aspects of the IPS products. I see a lot of people struggling to get started with IPS and this section is my attempt to gather what I have learned so others can benefit as well.

    To me nothing is more important than to share knowledge and help others. This section contain my findings and the things I have learned, but I still have much more to learn as well. Together we can learn and evolve the ways we customize the IPS products and while doing that there are no stupid questions. In the forum you can ask any question and we will try our best to answer them.

    Go to the IPS Forum ->
  • Cookies in IPS

    Jimi Wikman

    Cookies are quite useful for certain things, but it is not always clear on how to set or use Cookies. In the documentation there is a short section on how to use the IPS JS Utilities when working with cookies:

    ips.utils.cookie.set( 'myKey', 'Hello world', true ); // Sets a sticky cookie
    ips.utils.cookie.get( 'myKey' );
    // -> Hello world
    ips.utils.cookie.unset( 'myKey' );
    ips.utils.cookie.get( 'myKey' );
    // -> undefined

    You can also use a similar way to work with Cookies in PHP using the following format:

    {{\IPS\Request::i()->setCookie( 'name', 'value' );}}

    This will result in an HTTP only cookie, but if you extend this a bit you can get something useful to fetch in your js calls as well.

    \IPS\Request::i()->setCookie('cookie_name', 'value', NULL, TRUE));

    Null refer to how long the cookie will remain and by defult NULL means that it will be alive for as long as the session is alive. You can add a time object there to make the cookie persist for a certain amount.

    \IPS\Request::i()->setCookie('cookie_name', 'value', \IPS\DateTime::create()->add(new \DateInterval('P7D')));

    In this example we add a 7day persistence to the cookie. You can also do this in JavaScript of course:

    var date = new Date();
    date.setDate(date.getDate() + 7);
    ips.utils.cookie.set('cookie_name', 'value', date.toUTCString());

    Here are some more information on the cookie classes in IPS:


    In PHP: \IPS\Request::i()->setCookie();

    	 * Set a cookie
    	 * @param	string				$name		Name
    	 * @param	mixed				$value		Value
    	 * @param	\IPS\DateTime|null	$expire		Expiration date, or NULL for on session end
    	 * @param	bool				$httpOnly	When TRUE the cookie will be made accessible only through the HTTP protocol
    	 * @param	string|null			$domain		Domain to set to. If NULL, will be detected automatically.
    	 * @param	string|null			$path		Path to set to. If NULL, will be detected automatically.
    	 * @return	bool
    	public function setCookie( $name, $value, $expire=NULL, $httpOnly=TRUE, $domain=NULL, $path=NULL )


    In JavaScript: ips.utils.cookie.set()

    		 * Set a cookie value
    		 * @param	{string} 	cookieKey 	Key to set
    		 * @param 	{mixed} 	value 		Value to set in this cookie
    		 * @param 	{boolean} 	sticky 		Whether to make this a long-lasting cookie
    		 * @returns {void}
    		set = function( cookieKey, value, sticky )



    User Feedback

    Recommended Comments

    There are no comments to display.

    Please sign in to comment

    You will be able to leave a comment after signing in

    Sign In Now

  • Create New...