/go/sessioncookielifetime: sessioncookielifetime from the Command Line

session.cookie_lifetime is the number of seconds PHP tells the visitor's browser to keep the session cookie. PHP's own default is 0, which means the cookie is deleted when the browser closes. With a larger value, visitors stay logged in after closing and reopening the browser. /go/sessioncookielifetime changes this one setting in every php.ini file on the server (all installed PHP versions) with a single command. It can: Every admin action in GoAdmio has a matching /go/ command, so anything you can click you can also script.

Quick start

# Set 8 hours (the default value)
/go/sessioncookielifetime

# Set one day
/go/sessioncookielifetime 86400

# Back to PHP's default: cookie ends when the browser closes
/go/sessioncookielifetime 0

# Show the current value
/go/sessioncookielifetime return

Arguments

Argument Required Default Notes
seconds No 28800 The new value, in seconds. 0 means until the browser closes.
return No — Print the current value and change nothing. Case-insensitive.
You pass Result
Nothing Sets 28800 (8 hours).
An option starting with -- Ignored. Sets 28800.
A number, such as 86400 Sets that number.
0 Sets 0: the cookie ends when the browser closes.
return, Return, or RETURN Prints the current value.
More than one word All the words are joined with spaces and written as the value.

[!WARNING]
The value is not checked. Text, a negative number, or several arguments are all written to php.ini as they are, which can leave PHP with an invalid setting. Pass a single whole number.

Common values

Seconds Length
0 Until the browser closes (PHP’s own default)
3600 1 hour
28800 8 hours (this command’s default)
86400 1 day
604800 7 days
2592000 30 days

Examples

# Keep visitors' cookies for 8 hours on every PHP version
/go/sessioncookielifetime

# Keep visitors logged in for one day (set the server-side lifetime too)
/go/sessioncookielifetime 86400
/go/sessiongcmaxlifetime 86400

# End the cookie when the browser closes
/go/sessioncookielifetime 0

# Read the current value into a script variable
Value=$(/go/sessioncookielifetime return)
echo "$Value"

# Review recent calls
tail /var/log/go/sessioncookielifetime.log

Output

Setting a value

session.cookie_lifetime updated successfully.

This line is printed even if no php.ini file was found or changed. It does not mean the setting was verified.

Reading the value

28800

Only the number is printed. See How return works.

Unknown operating system

Unknown operating system.

Nothing is changed.

See the full reference at /go/sessioncookielifetime and the GoAdmio command index.

GoAdmio is free and open source, with no license fees and no account limits. Read the GoAdmio docs, or see why it is a free cPanel alternative at goadmio.com.

By:

Posted in:


Leave a Reply

Your email address will not be published. Required fields are marked *