--- warning: This file is auto generated by `yarn web:inject`, do not edit by hand examples: - setcookie('author_name', 'Kevin van Zonneveld') returns: - 'true' dependencies: - php/network/setrawcookie authors: original by: - Jonas Raoni Soares Silva (https://www.jsfromhell.com) improved by: - Kevin van Zonneveld (https://kvz.io) bugfixed by: - Andreas - Onno Marsman (https://twitter.com/onnomarsman) notes: [] parityVerified: - PHP 8.3 isTypescript: true type: function layout: function title: PHP's setcookie in TypeScript description: >- Here's what our current TypeScript equivalent to PHP's setcookie looks like. function: setcookie category: network language: php permalink: php/network/setcookie/ alias: - /functions/php/setcookie/ - /functions/network/setcookie/ - /php/setcookie/ - /functions/setcookie/ ---
{% codeblock lang:typescript %}import { setrawcookie } from '../network/setrawcookie.ts' export function setcookie( name: string, value: string, expires?: string | number | Date | null, path?: string | null, domain?: string | null, secure?: boolean, ): boolean { // discuss at: https://locutus.io/php/setcookie/ // parity verified: PHP 8.3 // original by: Jonas Raoni Soares Silva (https://www.jsfromhell.com) // bugfixed by: Andreas // bugfixed by: Onno Marsman (https://twitter.com/onnomarsman) // improved by: Kevin van Zonneveld (https://kvz.io) // example 1: setcookie('author_name', 'Kevin van Zonneveld') // returns 1: true return setrawcookie(name, encodeURIComponent(value), expires, path, domain, secure) } {% endcodeblock %}