Skip to content
View in the app

A better way to browse. Learn more.

JimiWikman.se

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Cookies in IPS

  • Owner

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 )

 


View full record

  • Views 1.3k
  • Created
  • Last Reply

Featured Replies

No posts to show

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.