<?php
$myDomain='myDomain.com';
session_set_cookie_params(0, '/', '.' . $myDomain.'');
session_start();
if ( isset($_SESSION['mySession']) ) {
echo 'mySession is already set';
} else {
echo 'mySession will be set';
$_SESSION['mySession']=1;
}
If I open the page for the first time, it says, “mySession will be set”.
and I open the page again, it says “mySession is already set”.
So far so good.
But it is in the PHP5.
I have another server which is in the PHP7.
Same code is in the PHP7.
Whenever I open the page, it continuously says “mySession will be set”.
Although “mySession” is set, it seems not pass over to the next openning.
How can I make “mySession” pass over to a next page?
I added the problem code above for sub-domains.
In order to make the sessions and cookies works as same to all sub-domains of myDomain.com, for example, sub1.myDomain.com, sub2.myDomain.com.
The code1 below says " Fatal error : Uncaught Error: Call to undefined function errot_reporting() in sessionTest:4 Stack trace: #0 {main} thrown on line 4 code1
<?php
declare(strict_types=1);
errot_reporting(-1);
ini_set('display_errors', '1');
$myDomain='myDomain.com';
session_set_cookie_params(0, '/', '.' . $myDomain.'');
session_start();
if ( isset($_SESSION['mySession']) ) {
echo 'mySession is already set';
} else {
echo 'mySession will be set';
$_SESSION['mySession']=1;
And the code2 below which is without the semicolon( says " Parse error : syntax error, unexpected ‘ini_set’ (T_STRING) in sessionTest.php on line 5 code2
<?php
declare(strict_types=1);
errot_reporting(-1)
ini_set('display_errors', '1');
$myDomain='myDomain.com';
session_set_cookie_params(0, '/', '.' . $myDomain.'');
session_start();
if ( isset($_SESSION['mySession']) ) {
echo 'mySession is already set';
} else {
echo 'mySession will be set';
$_SESSION['mySession']=1;
The code below works fine, I can see “mySession is already set”
Thank you, rpkamp.
<?php
declare(strict_types=1);
error_reporting(-1);
ini_set('display_errors', '1');
session_set_cookie_params(0, '/', '.dot.kr');
session_start();
if ( isset($_SESSION['mySession']) ) {
echo 'mySession is already set';
} else {
echo 'mySession will be set';
$_SESSION['mySession']=1;
}
By the way, dot.kr is activated when I test it
When I test it, the server connected to real IP.
But mostly the server is connected to a router for internet connection.
That is one reason why my test is so slow.