1

私は、ユーザーが独自のサブドメインを動的に作成できる Web プロジェクトに取り組んでいました。サブドメインを作成する前に、Web サイトにログインする必要があります。そして今、ユーザーがアクセスするサブドメインでもアクティブなユーザーのセッション変数を設定する方法を考えていました。session_set_cookie_params(0, '/', '.example.com'); のような多くの関数で試しました 。 **ini_set('session.cookie_domain', '.example.com');**

しかし、すべて無駄ではありません。機能はありません。ですから、これを処理する方法を教えてください。

これは、ユーザーがログインするとすぐにセッションを開始する私のコードです: checkusrlog.php

<?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 = '';

// セッション変数と Cookie 変数が設定されていない場合、このコードが実行されます

if (!isset($_SESSION['idx'])) { 
  if (!isset($_COOKIE['idCookie'])) {
     $logOptions = '<a href="http://' . $dyn_www . '/index.php">Register Account</a>
     &nbsp;&nbsp; | &nbsp;&nbsp; 
     <a href="http://' . $dyn_www . '/index.php">Log In</a>';
   }
}

// セッション ID が Cookie なしでログインしているユーザーに設定されている場合、meremember me 機能セット

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;

?>

注: すべてのサブドメインは、その特定のサブドメインに属するデータがサブドメインに基づいてデータベースから動的にダンプされる単一のコードのみで管理されます。

その間、共有ホスティング サービスに取り組んでおり、*.streamicon.com をルート ドメインとして使用しています。*.streamicon.com をルート ドメインとして使用すると、「n」個のサブドメインを動的に作成できるようになります。

4

0 に答える 0