use session_name("sample_websiteN");
before session_start()
(replace N with 1 or 2), see php.net/session_name
in localhost/sample_website1/index.php
<?php
session_name("sample_website1");
session_start();
if(isset($_SESSION['user'])){
header("location:home.php")
}
// This code redirects index.php to home.php if the session already exists
.........next lines are login code..........
//
//
//
............................................
in localhost/sample_website2/index.php
<?php
session_name("sample_website2");
session_start();
if(isset($_SESSION['user'])){
header("location:home.php")
}
// This code redirects index.php to home.php if the session already exists
.........next lines are login code..........
//
//
//
............................................
Explanation from php.net: The session name references the name of the session, which is used in cookies and URLs (e.g. PHPSESSID)
With this solution, you can deploy your code in same domain and in different domain with perfectly same behavior. You can host both directory in localhost/sample_website1/index.php and localhost/sample_website2/index.php OR in sample_website1.com/index.php and sample_website2.com/index.php with same code
If the session name seems ugly to be hardcoded, then save the session name string somewhere in a configuration file
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…