Php 使会话变量在动态创建的子域上处于活动状态
我在做一个web项目,它允许用户动态创建自己的子域。 在创建子域之前,他们应该登录到网站。 现在想知道如何设置用户的会话变量,即使在他访问的子域上也是如此。 尝试了很多功能,比如 会话设置cookie参数(0,“/”,“.example.com”)强> **ini_集('session.cookie_domain','.example.com');** 但这一切都是徒劳的。没有任何功能可以工作。 所以请建议我如何处理这件事 这是我的代码,用户登录后立即启动会话: checkusrlog.phpPhp 使会话变量在动态创建的子域上处于活动状态,php,database,Php,Database,我在做一个web项目,它允许用户动态创建自己的子域。 在创建子域之前,他们应该登录到网站。 现在想知道如何设置用户的会话变量,即使在他访问的子域上也是如此。 尝试了很多功能,比如 会话设置cookie参数(0,“/”,“.example.com”) **ini_集('session.cookie_domain','.example.com');** 但这一切都是徒劳的。没有任何功能可以工作。 所以请建议我如何处理这件事 这是我的代码,用户登录后立即启动会话: checkusrlog.php &l
<?php
//for session to be active on subdomain
session_set_cookie_params(0, '/', '.xyz.com');
session_start(); // Start Session First Thing
error_reporting(E_ALL);
ini_set('display_errors', '1');
include_once "connectiontomysql.php"; // Connect to the database
$dyn_www = $_SERVER['HTTP_HOST'];
//------ CHECK IF THE USER IS LOGGED IN OR NOT AND GIVE APPROPRIATE OUTPUT -------
$logOptions = ''; // Initialize the logOptions variable that gets printed to the page
$newMessage = '';
注意:所有子域仅使用一段代码进行管理,其中属于该特定子域的数据根据子域从数据库中动态转储
在这期间,我正在使用共享主机服务,并将*.streamicon.com用作根域。使用*.streamicon.com作为我的根域,因为它允许我动态创建“n”个子域。请参阅
if (!isset($_SESSION['idx'])) {
if (!isset($_COOKIE['idCookie'])) {
$logOptions = '<a href="http://' . $dyn_www . '/index.php">Register Account</a>
|
<a href="http://' . $dyn_www . '/index.php">Log In</a>';
}
}
if (isset($_SESSION['idx'])) {
$decryptedID = base64_decode($_SESSION['idx']);
$id_array = explode("p3h9xfn8sq03hs2234", $decryptedID);
$logOptions_id = $id_array[1];
} else if (isset($_COOKIE['idCookie'])) {// If id cookie is set, but no session ID is set yet, we set it below and update stuff
$decryptedID = base64_decode($_COOKIE['idCookie']);
$id_array = explode("nm2c0c4y3dn3727553", $decryptedID);
$userID = $id_array[1];
$userPass = $_COOKIE['passCookie'];
// Get their user first name to set into session var
$sql_uname = mysql_query("SELECT username, email FROM siteMembers WHERE id='$userID' AND password='$userPass' LIMIT 1");
$numRows = mysql_num_rows($sql_uname);
if ($numRows == 0) {
// Kill their cookies and send them back to homepage if they have cookie set but are not a member any longer
setcookie("idCookie", '', time()-42000, '/');
setcookie("passCookie", '', time()-42000, '/');
header("location: index.php"); // << makes the script send them to any page we set
exit();
}
while($row = mysql_fetch_array($sql_uname)){
$username = $row["username"];
$useremail = $row["email"];
}
$_SESSION['id'] = $userID; // now add the value we need to the session variable
$_SESSION['idx'] = base64_encode("g4p3h9xfn8sq03hs2234$userID");
$_SESSION['username'] = $username;
$_SESSION['useremail'] = $useremail;
$_SESSION['userpass'] = $userPass;
$logOptions_id = $userID;