my code is simple:
<?php
session_start();
session_regenerate_id();
?>
When the first time I request this page, the HTTP request with no cookie, then it will response with two 'set-cookie:PHPSESSID=xxxxxx' Then I thought that I may write code like this:
<?php
session_start();
if(!empty($_SERVER['HTTP_COOKIE'])){
session_regenerate_id();
}
?>
While then, whether my HTTP request with cookie: PHPSESSID=xxxxxx or not, it will responses with only one 'set-cookie:PHPSESSID=xxxxxx'
However, my solution is very awkward. Any professional PHPer can tell me, how to write a professional code to handle the problem which is the HTTP request may with cookie 'PHPSESSID' or without cookie 'PHPSESSID'.
Have a look at session_start()
session_start() creates a session or resumes the current one based on a session identifier passed via a GET or POST request, or passed via a cookie.
So when you not want that PHPSESSION
-Cookie you need to remove session_start()
Set cookie with setcookie('cookie_name', 'some_value') and then get the cookie with $_COOKIE['cookie_name']. Check difference for cookie and session so you are sure you need a cookie for your operation :)