原谅我不知道,但'虚拟主机配置'是什么。我的代码的运行是这样的:
主要页面将包括session.php
function Session()
{
$this->time = time();
$this->startSession();
}
function startSession()
{
global $serverFunctions;
$serverFunctions->setSubdomainSharing();
session_start();
$this->checkSessionLife();
//check if user is logged in
$this->logged_in = $this->checkLogin();
//if user is not logged in then it is given guest credintials
if (!$this->logged_in)
{
$this->user_name = $_SESSION['user_name'] = GUEST_NAME;
$this->user_level = $_SESSION['user_level'] = GUEST_LEVEL;
}
if (!isset($_SESSION['language']))
{
$this->setLanguage("translation_english");
}
else
{
$this->user_language = $_SESSION['language'];
}
}
function checkSessionLife()
{
global $serverFunctions;
if (isset($_SESSION['start_time']))
{
$session_life = time() - $_SESSION['start_time'];
if ($session_life > 15)
{
$this->logout();
$serverFunctions->setSubdomainSharing();
session_start();
}
}
else if (!isset($_SESSION['start_time']))
{
//logout any session that was created
//before expiry was implemented
$this->logout();
$serverFunctions->setSubdomainSharing();
session_start();
}
$_SESSION['start_time'] = time();
}
function logout()
{
global $database;
// Unset session variables
session_destroy();
session_unset();
//session_regenerate_id(true);
$this->logged_in = false;
// Set user level to guest
$this->user_name = GUEST_NAME;
$this->user_level = GUEST_LEVEL;
}
会话文件包括一个名为serverFunctions
另一个PHP文件。这只是一个允许我格式化URL等的类。
function getAddressPrefix()
{
$address_prefix = "";
if ($_SERVER['SERVER_ADDR'] == '127.0.0.1')
{
$address_prefix = "http://localhost/myproject";
}
else
{
$address_prefix = $this->getServerName();
}
return $address_prefix;
}
function getServerName()
{
return "http://" . str_replace("www.", "", $_SERVER['SERVER_NAME']);
}
function formatRequestingPage()
{
return $this->getServerName() . $_SERVER['SCRIPT_NAME'];
}
function setSubdomainSharing()
{
if ($_SERVER['SERVER_ADDR'] != '127.0.0.1')
{
$domain = $this->getServerName();
do
{
$domain = substr($domain, strpos($domain, ".", 0) + 1);
}
while (substr_count($domain, ".") > 1);
$domain = ".".$domain;
ini_set("session.cookie_domain", $domain);
}
}
当用户登录时,登录请求被process_request.php
function LoginReq()
{
global $session;
global $variables;
global $serverFunctions;
$retval = $session->login($_POST['user_name'], $_POST['password']);
if ($retval)
{
header("Location: " . $serverFunctions->getAddressPrefix());
exit();
}
else
{
$_SESSION['variables_array'] = $_POST;
$_SESSION['error_array'] = $variables->getErrorArray();
header("Location: " . $serverFunctions->getAddressPrefix() . "/login/");
exit();
}
}
如果我错过什么或需要解释发生的事情多一点让我知道处理。
我无法将此代码添加到此回复消息中,因此我为此主题创建了一个新答案,希望代码易于遵循。 – michaeln31 2011-03-09 18:35:30
我无法访问我的服务器的那部分,这就是为什么我一直在尝试使用ini_set。我将与我的供应商联系并询问他们。 ini_set应该不工作? – michaeln31 2011-03-12 15:58:23