自定义会话变量在FF中丢失

时间:2011-12-28 作者:scarhand

无论出于何种原因,firefox正在删除我的自定义会话变量。这些变量用于内置到自定义主题中的自定义用户系统。这只发生在firefox中,用户系统在所有其他浏览器中都能完美工作。

这是我的页眉顶部。php:

<?php

session_start();

global $errors, $success, $u_cache;

include \'sub-user-auth.php\';

?>
这是子用户身份验证。php:

<?php

$u_cache[\'logged_in\'] = false;

if (!empty($_POST[\'u_signin\']))
{
    $errors = array();
    $success = \'\';

    foreach ($_POST as $k => $v)
        $$k = trim(htmlspecialchars($v, ENT_QUOTES));

    if (empty($u_username)) 
        $errors[] = \'You must enter your username\';
    else if (empty($u_password)) 
        $errors[] = \'You must enter your password\';
    else if (mysql_result(mysql_query("select count(*) from `users` where `username`=\'".mysql_real_escape_string($u_username)."\' and `password`=\'".md5($u_password)."\'"), 0) == 0)
        $errors[] = \'Invalid username and/or password entered\';

    if (empty($errors))
    {
        foreach ($_POST as $k => $v)
            $$k = trim($v);

        $_SESSION[\'u_username\'] = $u_username;
        $_SESSION[\'u_password\'] = md5($u_password);

        if ($u_remember == \'yes\')
        {
            setcookie(\'u_username\', $u_username, time() + 31536000);
            setcookie(\'u_password\', md5($u_password), time() + 31536000);           
        }

        $success = \'You have been signed in successfully! Please <b><a href="\'.get_bloginfo(\'url\').\'/my-home">click here</a></b> to continue to your account.\';

        foreach ($_POST as $k => $v)
            $$k = \'\';
    }
}

if (!empty($_COOKIE[\'u_username\']) && !empty($_COOKIE[\'u_password\']))
{
    $u_cache[\'u_username\'] = $_COOKIE[\'u_username\'];
    $u_cache[\'u_password\'] = $_COOKIE[\'u_password\'];
}
else if (!empty($_SESSION[\'u_username\']) && !empty($_SESSION[\'u_password\']))
{
    $u_cache[\'u_username\'] = $_SESSION[\'u_username\'];
    $u_cache[\'u_password\'] = $_SESSION[\'u_password\'];
}

if (!empty($u_cache[\'u_username\']) && !empty($u_cache[\'u_password\']))
{
    $sql = mysql_query("select * from `users` where `username`=\'".mysql_real_escape_string($u_cache[\'u_username\'])."\' and `password`=\'".mysql_real_escape_string($u_cache[\'u_password\'])."\'");

    if (mysql_num_rows($sql) != 0)
    {
        while ($row = mysql_fetch_assoc($sql))
        {
            foreach ($row as $k => $v)
                $u_cache[$k] = htmlspecialchars(stripslashes($v), ENT_QUOTES);
        }

        $u_cache[\'logged_in\'] = true;
        $u_cache[\'fav_leagues\'] = explode(\',\', $u_cache[\'fav_leagues\']);
        $u_cache[\'fav_teams\'] = explode(\',\', $u_cache[\'fav_teams\']);
    }
}

if ($u_cache[\'logged_in\'])
{
    if (is_page(array(\'sign-in\', \'sign-up\', \'forgot-password\')))
    {
        header(\'Location: \'.get_bloginfo(\'url\').\'/my-home\');
        die();
    }
}
else
{
    if (is_page(array(\'my-home\', \'edit-home\', \'sign-out\')))
    {
        header(\'Location: \'.get_bloginfo(\'url\').\'/sign-in\');
        die();
    }
}

?>
它允许我登录,显示“我的主页”,然后几乎立即将我踢出,并将我发送回登录页面。将删除所有自定义会话变量。

1 个回复
SO网友:tamilsweet

你确定它可以在其他浏览器中使用吗?

默认情况下,WordPress会删除/取消设置所有未知变量。检查wp-includes/load.php 函数内部wp_unregister_GLOBALS().

我有类似的会话变量问题,并使用(在functions.php中)修复了它

<?php
// Enable session
add_action(\'init\', \'custom_init_session\', 1);
function custom_init_session() {
    if (!session_id())
        session_start();
}
ie.电话session_start() 在期间init 而不是在标题中。php。

试试看!

结束

相关推荐

Admin Theme customization

我遵循wordpress codex网站上关于通过插件创建管理主题的说明。我激活了插件,但我的样式表没有包含在<head>.. 这是我的代码:add_action( \'admin_init\', \'kd_plugin_admin_init\' ); add_action( \'admin_menu\', \'kd_plugin_admin_menu\' ); function kd_plugin_admin_init() { /* Register