Answer the question
In order to leave comments, you need to log in
How to correctly pass the 6th argument to the setcookie() function and how to understand it?
ATTENTION! Below is a stream of noob questions!
Hello! I'm using openserver and don't have a complete understanding of the domain name and server name. As far as I know the domain provided to the setcookie() function must match the end of the server name. But what is my server name then? asd? As the 6th argument, you can specify the domain to which these cookies will be available.
My "site" is located along this path http://asd/.
(what kind of path is this in general? The path to the server? Then what is my server name?)
I write like this -
setcookie("cookiewithdomain", "ralph", 0, "/files.php", ".asd"); //С точкой не работает
setcookie("cookiewithdomain", "ralph", 0, "/files.php", "asd"); //Без точки работает
Answer the question
In order to leave comments, you need to log in
RTFM ru2.php.net/manual/ru/function.setcookie.php
There is a clear description of what path, domain are and what values to specify there.
Come on?
Your question:
Open the documentation and read:
path
Path to the directory on the server from which the cookies will be available. If set to '/', cookies will be available in the entire domain. If set to '/foo/', cookies will only be available from the /foo/ directory and all its subdirectories (for example, /foo/bar/) of the domain. The default value is the current directory where the cookie is set.
domain
(Sub) domain to which cookies are available. Specifying a subdomain (eg 'www.example.com') will make the cookie available in it and all its subdomains (eg w2.www.example.com). To make cookies available for an entire domain (including subdomains), you just need to specify the domain name (i.e. 'example.com').
secure
Specifies that the cookie value should be transmitted from the client over a secure HTTPS connection. If set to TRUE, the cookie will be passed from the client to the server only if a secure connection is established.
session_start();
$currentCookieParams = session_get_cookie_params();
$sidvalue = session_id();
if(!isset($_COOKIE['PHPSESSID'])) {
setcookie(
'PHPSESSID', //name
$sidvalue, //value
0, //expires at end of session
$currentCookieParams['path'], //path
$currentCookieParams['domain'], //domain
true //secure
);
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question