session_set_cookie_params / session_get_cookie_params

session_set_cookie_params(array|int $lifetime_or_options, ?string $path = null, ?string $domain = null, ?bool $secure = null, ?bool $httponly = null): bool — session_get_cookie_params(): array

Sets/reads the session cookie's security parameters (lifetime/path/domain/secure/httponly/samesite; 7.3+ options-array style); the effect lasts one request only and the call must run before session_start().

C C23

C23
#include <stdio.h>
#include <string.h>

int main(void) {
    /* CGI layer: hand-write the session cookie's Set-Cookie attribute string */
    const char *attrs = "Domain=.example.com; Path=/; Secure; HttpOnly; SameSite=Lax";
    printf("Set-Cookie: sid=abc123; %s\n", attrs);
    /* attribute presence checks on the assembled string */
    int flagsOk = strstr(attrs, "Secure") && strstr(attrs, "HttpOnly") && strstr(attrs, "SameSite=Lax");
    printf("flags ok: %s\n", flagsOk ? "true" : "false");
    return 0;
}
Output
Set-Cookie: sid=abc123; Domain=.example.com; Path=/; Secure; HttpOnly; SameSite=Lax
flags ok: true

C++ C++26

C++26
#include <iostream>
#include <string>

int main() {
    // CGI layer: hand-write the session cookie's Set-Cookie attribute string
    const std::string attrs = "Domain=.example.com; Path=/; Secure; HttpOnly; SameSite=Lax";
    std::cout << "Set-Cookie: sid=abc123; " << attrs << "\n";
    // attribute presence checks on the assembled string
    const bool flagsOk = attrs.find("Secure") != std::string::npos
        && attrs.find("HttpOnly") != std::string::npos
        && attrs.find("SameSite=Lax") != std::string::npos;
    std::cout << "flags ok: " << (flagsOk ? "true" : "false") << "\n";
    return 0;
}
Output
Set-Cookie: sid=abc123; Domain=.example.com; Path=/; Secure; HttpOnly; SameSite=Lax
flags ok: true

C# v11.0.100

v11.0.100
// The framework equivalent is ASP.NET's CookieOptions passed to Response.Cookies.Append;
// at the language level hand-write the attribute string in the customary order
string attrs = "Domain=.example.com; Path=/; Secure; HttpOnly; SameSite=Lax";
Console.WriteLine("Set-Cookie: sid=abc123; " + attrs);
string[] parts = attrs.Split("; ");
Console.WriteLine("flags ok: " + (parts.Contains("Secure") && parts.Contains("HttpOnly") && parts.Contains("SameSite=Lax")));
Output
Set-Cookie: sid=abc123; Domain=.example.com; Path=/; Secure; HttpOnly; SameSite=Lax
flags ok: True

Go v1.27.4

v1.27.4
package main

import (
	"fmt"
	"net/http"
	"net/http/httptest"
)

func main() {
	// The standard library is the framework-grade equivalent: http.Cookie carries every
	// security attribute and http.SetCookie serializes them (domain dot stripped for you)
	c := &http.Cookie{
		Name:     "sid",
		Value:    "abc123",
		Domain:   ".example.com",
		Path:     "/",
		Secure:   true,
		HttpOnly: true,
		SameSite: http.SameSiteLaxMode,
	}
	flagsOk := c.Secure && c.HttpOnly && c.SameSite == http.SameSiteLaxMode
	rec := httptest.NewRecorder()
	http.SetCookie(rec, c)
	fmt.Println("Set-Cookie:", rec.Header().Get("Set-Cookie"))
	fmt.Println("flags ok:", flagsOk)
}
Output
Set-Cookie: sid=abc123; Path=/; Domain=example.com; HttpOnly; Secure; SameSite=Lax
flags ok: true

Java v27.0.1

v27.0.1
public class Main {
    public static void main(String[] args) {
        // The Servlet Cookie API (jakarta.servlet.http) is framework-level; hand-write the attribute string
        String attrs = "Domain=.example.com; Path=/; Secure; HttpOnly; SameSite=Lax";
        System.out.println("Set-Cookie: sid=abc123; " + attrs);
        boolean flagsOk = attrs.contains("Secure") && attrs.contains("HttpOnly") && attrs.contains("SameSite=Lax");
        System.out.println("flags ok: " + flagsOk);
    }
}
Output
Set-Cookie: sid=abc123; Domain=.example.com; Path=/; Secure; HttpOnly; SameSite=Lax
flags ok: true

JavaScript v26.13.1

v26.13.1
// No built-in cookie API (express's res.cookie options object is the real counterpart);
// hand-write the attribute string in the customary order
const attrs = "Domain=.example.com; Path=/; Secure; HttpOnly; SameSite=Lax";
console.log("Set-Cookie: sid=abc123; " + attrs);
const parts = attrs.split("; ");
console.log("flags ok:", parts.includes("Secure") && parts.includes("HttpOnly") && parts.includes("SameSite=Lax"));
Output
Set-Cookie: sid=abc123; Domain=.example.com; Path=/; Secure; HttpOnly; SameSite=Lax
flags ok: true

PHP v8.6.0

v8.6.0
// Session cookie parameters: set with the 7.3+ options array, read back with session_get_cookie_params.
// The effect lasts for the current script only, and the call must run BEFORE session_start().
$ok = session_set_cookie_params([
    "lifetime" => 3600,
    "path" => "/",
    "domain" => "",
    "secure" => true,
    "httponly" => true,
    "samesite" => "Strict",
]);
$p = session_get_cookie_params();
echo "set: ", var_export($ok, true), "\n";
echo "lifetime: ", $p["lifetime"], "\n";
echo "path: ", $p["path"], "\n";
echo "secure: ", var_export($p["secure"], true), "\n";
echo "httponly: ", var_export($p["httponly"], true), "\n";
echo "samesite: ", $p["samesite"], "\n";
echo "attributes sent on the cookie: Secure; HttpOnly; SameSite=Strict";
Output
set: true
lifetime: 3600
path: /
secure: true
httponly: true
samesite: Strict
attributes sent on the cookie: Secure; HttpOnly; SameSite=Strict

Python v3.15.2

v3.15.2
from http.cookies import SimpleCookie

# Frameworks own the real settings (Flask's SESSION_COOKIE_SECURE/HTTPONLY/SAMESITE);
# the stdlib SimpleCookie serializes the full attribute set in its own fixed (alphabetical) order
c = SimpleCookie()
c["sid"] = "abc123"
c["sid"]["domain"] = ".example.com"
c["sid"]["path"] = "/"
c["sid"]["secure"] = True
c["sid"]["httponly"] = True
c["sid"]["samesite"] = "Lax"
print(c.output())
print("flags ok:", c["sid"]["secure"] and c["sid"]["httponly"] and c["sid"]["samesite"] == "Lax")
Output
Set-Cookie: sid=abc123; Domain=.example.com; HttpOnly; Path=/; SameSite=Lax; Secure
flags ok: True

Rust v1.99.1

v1.99.1
fn main() {
    // No cookie facilities in the standard library (the cookie crate / framework extractors in real projects);
    // hand-write the attribute string
    let attrs = "Domain=.example.com; Path=/; Secure; HttpOnly; SameSite=Lax";
    println!("Set-Cookie: sid=abc123; {}", attrs);
    let flags_ok = attrs.contains("Secure") && attrs.contains("HttpOnly") && attrs.contains("SameSite=Lax");
    println!("flags ok: {}", flags_ok);
}
Output
Set-Cookie: sid=abc123; Domain=.example.com; Path=/; Secure; HttpOnly; SameSite=Lax
flags ok: true

TypeScript v26.13.1

v26.13.1
// No built-in cookie API (express's res.cookie options object is the real counterpart);
// hand-write the attribute string in the customary order
const attrs: string = "Domain=.example.com; Path=/; Secure; HttpOnly; SameSite=Lax";
console.log("Set-Cookie: sid=abc123; " + attrs);
const parts: string[] = attrs.split("; ");
console.log("flags ok:", parts.includes("Secure") && parts.includes("HttpOnly") && parts.includes("SameSite=Lax"));
Output
Set-Cookie: sid=abc123; Domain=.example.com; Path=/; Secure; HttpOnly; SameSite=Lax
flags ok: true

Language differences

C: no session facilities — session-cookie parameters are just a config struct in a hand-rolled CGI/framework, serialized into a Set-Cookie attribute string.

C++: same as C.

C#: the framework layer is ASP.NET's CookieOptions (passed to Response.Cookies.Append): Secure/HttpOnly/SameSite/MaxAge/Domain/Path all included; at the language level hand-write the string.

Go: the standard library is the framework-grade equivalent — http.SetCookie plus http.Cookie (Secure/HttpOnly/SameSite/Domain/Path); note serialization strips the Domain's leading dot.

Java: the framework layer is Servlet's Cookie plus response.addCookie (jakarta.servlet.http), attributes assembled by the container; at the language level hand-write the string.

JavaScript: the framework layer is express's res.cookie(name, value, { secure, httpOnly, sameSite, domain, path }); in browsers document.cookie only takes a string, and HttpOnly is not settable from JS anyway.

PHP: session_set_cookie_params updates per-request runtime ini — the effect does not survive across requests, so call it before session_start() every time; the 7.3+ options array supports samesite, 8.5 adds partitioned (CHIPS); session_get_cookie_params() reads it back (the returned array gains a partitioned key in 8.5). Together with the setcookie entry it forms the complete cookie security picture.

Python: the framework layer is Flask's SESSION_COOKIE_SECURE/HTTPONLY/SAMESITE settings; the stdlib http.cookies.SimpleCookie serializes the full attribute set (output order fixed, alphabetical).

Rust: the framework layer is the cookie crate or an axum extractor: Cookie::build(("sid", "abc123")).secure(true).http_only(true).same_site(SameSite::Lax).

TypeScript: same as JavaScript.