Firefox losing session data

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Eric!
DevNet Resident
Posts: 1146
Joined: Sun Jun 14, 2009 3:13 pm

Re: Firefox losing session data

Post by Eric! »

Is Firefox blocking your cookies? Have you tried resetting firefox to the defaults? If your $_post data works, like mcinfo suggests checking then it is probably a config issue.

Another dubug tool I like to use is WebScarab. Configure it as a proxy and it will show you all the raw data exchanged between your browser and the server.
Belkorin
Forum Newbie
Posts: 11
Joined: Fri Jun 26, 2009 9:03 pm

Re: Firefox losing session data

Post by Belkorin »

I use the webdeveloper toolbar extension for firefox, and it shows me that my session cookie is intact, and the session id isn't getting lost, because the cookie doesn't change.
Belkorin
Forum Newbie
Posts: 11
Joined: Fri Jun 26, 2009 9:03 pm

Re: Firefox losing session data

Post by Belkorin »

So, I've commented everything out and uncommented until it broke, and found that the following function breaks the session data:

Code: Select all

function pl_template_sub($str, $template_data)
{
    $add_blank = true;
    $use_auto_menu = false;
 
    $pos = strpos($str, '%%[');
    
    // this might not work if a template field starts at the very beginning
    // of the template file (ie. $pos == 0)
    //      if ($pos === false)
    if (FALSE === $pos)
    {
        return $str;
    }
    
    // this value is flipped later if a menu is specified
    $use_auto_lookup = false;
    
    // first, get the name of the first template field
    $endpos = strpos($str, ']%%');
    
    // check $next_name for error conditions
    if ($pos > $endpos)
    {
        die(pl_html_error_notice("templating error", "templating error #1"));
    }
    
    if (($endpos - $pos) > 50)
    {
        die(pl_html_error_notice("templating error", "template field is missing end tag, or name is too large"));
    }
    
    $next_name = substr($str, $pos + 3, $endpos - $pos - 3);
    
    // handle menus
    // menus that should have a blank/NULL entry added
    if (strstr($next_name, ","))
    {
        $use_auto_lookup = true;
        
        $tag_name = '';
        $tag_lookup = '';
        $tag_mode = 'menu';
        
        $a = explode(",", $next_name);
        
        $tag_name = $a[0];
        
        if (array_key_exists(1, $a))
        {
            $tag_lookup = $a[1];
        }
        
        if (array_key_exists(2, $a))
        {
            $tag_mode = $a[2];
        }
    }
    
    // menus that don't need a blank entry added - for backwards compatibility
    else if (strstr($next_name, ";"))
    {
        $use_auto_lookup = true;
        
        list($tag_name, $tag_lookup) = explode(";", $next_name);
        $tag_mode = 'menu_no_blank';
    }
    
    if (true == $use_auto_lookup)
    {
        /*  This is a lookup tag, and so the value in $template_data[$next_name]
        needs to be replaced by the lookup value or by HTML code
        */
        if (array_key_exists($tag_name, $template_data))
        {
            $tag_value = $template_data[$tag_name];
        }
        
        else
        {
            $tag_value = null;
        }
        
        // Get the menu array
        $menu_array = pl_menu_get($tag_lookup);
        
        
        $x = '';
        // Determine what to draw based on $tag_mode
        switch ($tag_mode)
        {
            case 'text':
            
            $x = pl_array_lookup($tag_value, $menu_array);
            
            break;
            
            
            case 'radio':
            
            foreach ($menu_array as $key => $val)
            {
                if ($key == $tag_value)
                {
                    $checked = ' checked';
                }
                
                else
                {
                    $checked = '';
                }
                
                $x .= "<input type=\"radio\" name=\"$tag_name\" value=\"$key\" tabindex=\"1\"{$checked}>{$val} &nbsp; ";
            }
            
            break;
            
            
            case 'checkbox':
            
            if ('yes_no' != $tag_lookup)
            {
                break;
            }
            
            if (1 == $tag_value)
            {
                $checked = ' checked';
            }
            
            else
            {
                $checked = '';
            }
            
            // Assigning two fields the same name may not be compatible with all browsers.  May not be compliant with W3C standards, either.
            $x .= "<input type=\"hidden\" name=\"$tag_name\" value=\"0\">";
            $x .= "<input type=\"checkbox\" name=\"$tag_name\" value=\"1\" tabindex=\"1\"{$checked}>\n";
            
            break;
            
            
            case 'menu_no_blank':
            
            $x = pl_html_menu($menu_array, $tag_name, $tag_value, 0);
            
            break;
            
            
            case 'menu':
            
            $x = pl_array_menu($menu_array, $tag_name, $tag_value, 1);
            
            break;
            
            
            default:
            
            $x = 'INVALID MENU MODE';
            
            break;
        }
        
        $template_data[$next_name] = $x;
    }
    
    // Check that the key exists in the template data, to avoid triggering a PHP warning
    if (array_key_exists($next_name, $template_data))
    {
        // we have the name, now replace the first and any additional fields
        $newstr = str_replace("%%[$next_name]%%", $template_data[$next_name], substr($str, $pos));
    }
    
    else
    {
        $newstr = str_replace("%%[$next_name]%%", '', substr($str, $pos));
    }
    
    // now proceed to next template field in $str
    return substr($str, 0, $pos) . pl_template_sub($newstr, $template_data);
}
Specifically, when I comment out the return line, it doesn't break, but if I let it do the recursion, it does.
Belkorin
Forum Newbie
Posts: 11
Joined: Fri Jun 26, 2009 9:03 pm

Re: Firefox losing session data

Post by Belkorin »

I'm not sure I have access to the apache configuration for the server that it doesn't work on, but I compared the output from phpinfo() and the only significant difference that I found between them is:

working server:
Server API: Apache 2.0 Handler

failing server:
Server API: CGI/FastCGI

Also, the failing server has the following .htaccess file to force an SSL connection:

Code: Select all

 
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.********.org/$1 [R,L]
 
Belkorin
Forum Newbie
Posts: 11
Joined: Fri Jun 26, 2009 9:03 pm

Re: Firefox losing session data

Post by Belkorin »

Hmm...things seem to have gone silent. Is everyone as clueless on this as I am?
Post Reply