I have tried every method to start a session in sub domain but is not working
Here is sample of my php login code
<?php
if(isset($_POST['login'])){
$username = $_POST['login'];
//Database Query
if($everythingIsOkay){
session_set_cookie_params(0, "/", ".example.com", false, false);
session_start();
$_SESSION['username'] = $username;
$_SESSION['ini'] = true;
session_id();
header('Location:accountt.php');
}
}?>
Then I use this on top of every page in main domain
session_start();
This on sub.example.com i put this at the top of every file
<?php
session_set_cookie_params(0, "/", ".example.com", false, false);
session_start();
?>
But still is not working can someone tell me what to do?
Lastly i make this function and session is working in sub-domain but out in main domain
I added below function at the top of login script
<?php
function new_session_start(){
session_name();
$secure = false;
// This stops JavaScript being able to access the session id.
$httponly = false;
// Gets current cookies params. //$cookieParams["domain"],$cookieParams["lifetime"]
$cookieParams = session_get_cookie_params();
session_set_cookie_params(0,
$cookieParams["path"],
'.example.com',
$secure,
$httponly);
session_start(); // Start the PHP session
session_regenerate_id(true); // regenerated the session, delete the old one.
}
new_session_start();
?>
Then use this at the top of subdomain page
<?php
session_set_cookie_params(0, "/", ".example.com", false, false);
session_start();
session_regenerate_id(true);
?>