Redirect to a subdomain and keep the session started with PHP

3

I would like to know if it is possible to keep the session with which you entered the system and send it to a subdomain and if possible, in what way can I do this event?

That is, if a user logs in dominio.com and clicks on a button which redirects it to sub.dominio.com

How can I make the session stay active in sub.dominio.com ?

    
asked by cesg.dav 17.08.2018 в 20:51
source

3 answers

2

In both scripts, try:

ini_set('session.cookie_domain', '.tudominio.com');

or editing the php.ini (the php.ini if they are different php installations for each subdomain)

session.cookie_domain = ".tudominio.com"

the . ahead is important for you to take the subdomains

    
answered by 17.08.2018 в 21:29
0

this example can help you

mydomain.com you are logged in this domain

$_SESSION['usuario']

mydomain.com your session is still active in this domain

<?php 
session_start();

if(!isset($_SESSION["usuario"])){
    echo 'Usted no esta logueado';
    exit;
}else{
  echo 'Usted esta logueado';
}
    
answered by 17.08.2018 в 21:05
0

You can save the data in the main domain within a cookie with setcookie () and use them in the subdomain to start the session again with session_start (). This data is stored in the global variables $ _COOKIE and $ _SESSION.

PHP Documentation: link

link

I hope it works. Greetings!

    
answered by 18.08.2018 в 06:23