0

I made a login system and set the user panel to the subdomain, but I can't get the session information in the subdomain.

My codes:

domain.com->login.php:

<?php
  //Login Processes
  ini_set('session.cookie_domain', '.domain.com' );
  session_start();
  $_SESSION["login"] = "ok";
  $_SESSION["user"] = "wh1z";
  header("Location: https://subdomain.domain.com")
?>

subdomain.domain.com->index.php:

<?php 
  if($_SESSION["login"]){
    echo "Welcome, ".$_SESSION["user"];
  }else{
    echo "You Don't Have Permission";
  }
?>
Felix
  • 571
  • 14
  • 34
wh1z
  • 1

1 Answers1

0

The session itself has little to do with your domains.

  1. The session is identified by a cookie with the session id (or passed in the url).
  2. The cookie has to do with domains: you can make a cookie to be accessible in subdomains, but for that you will probably need to modify a php ini setting (session.cookie_domain)
  3. And now let's suppose that the subdomain is hosted on the same server, and you don't need to share session data between hosts - you still have to be careful not to override gathered session.

Read these for more details, and you will get the point: