Current location: Hot Scripts Forums » Programming Languages » PHP » Cookie Problem in IE


Cookie Problem in IE

Reply
  #1 (permalink)  
Old 12-12-07, 09:54 AM
coolmark18's Avatar
coolmark18 coolmark18 is offline
Newbie Coder
 
Join Date: Oct 2005
Posts: 94
Thanks: 0
Thanked 0 Times in 0 Posts
Cookie Problem in IE

Hi guys.

I have a site which allows the user to change size of text. I do this by having 4 separate styles. I use PHP to take the users choice, save a cookie and then check for this cookie to selected which Style Sheet to use.

This code works brilliantly with FireFox, however, doesnt seem to work At All with Internet Explorer. I cant even find a cookie stored on my computer.

Any help would be great,

Mark

Code on Every single page:
PHP Code:

<?php

    $inTwoMonths 
60 60 24 60 time(); 
    

        switch (
$_GET[textsize]){
            case 
"large":
                
setcookie('text''large'$inTwoMonths); 
                break;
            case 
"med":
                
setcookie('text''med'$inTwoMonths); 
                break;    
            case 
"reg":
                
setcookie('text''reg'$inTwoMonths); 
                break;    
            case 
"text":
                
setcookie('text''text'$inTwoMonths); 
                break;
        }
        switch (
$_COOKIE[text]){
            case 
"large":
                
$selectedstyle "larger.css";
                break;
            case 
"med":
                
$selectedstyle "large.css";
                break;    
            case 
"reg":
                
$selectedstyle "normal.css";
                break;    
            case 
"text":
                
$selectedstyle "textonly.css";
                break;
            default:
                
$selectedstyle "normal.css";
                break;
        }
?>
Selection code on the accessability page:
PHP Code:

                <form name="form1" method="get" action="confirmsize.php">

                  <
p>
                    <
label>
                    <
input type="radio" name="textsize" value="large">
                  
Large</label>
                    <
br>
                    <
label>
                    <
input type="radio" name="textsize" value="med">
                  
Med</label>
                    <
br>
                    <
label>
                    <
input type="radio" name="textsize" value="reg">
                  
Regular</label>
                    <
br>
                    <
label>
                    <
input type="radio" name="textsize" value="text"
                    
Text Only </label><br>
                    <
input type="submit" name="Submit" value="Submit">
                  </
p>
                </
form
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 12-12-07, 10:00 AM
UnrealEd's Avatar
UnrealEd UnrealEd is offline
Community Liaison
 
Join Date: May 2005
Location: Antwerp, Belgium
Posts: 3,165
Thanks: 4
Thanked 25 Times in 25 Posts
PHP is browser independent, so switching browsers can't change a thing to the execution of the code. However: make sure cookies are enabled in the IE browser, maybe that's the problem
__________________
"Good judgement comes from experience, and experience comes from bad judgement." - Fred Brooks

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 12-12-07, 10:14 AM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,074
Thanks: 11
Thanked 88 Times in 83 Posts
Note that $_COOKIE['xxx'] is not available directly after setting the cookie via secookie(). You have to send another request to the server so that it sends the newly received cookies as well.

EDIT:

Try this.
PHP Code:

$inTwoMonths 60 60 24 60 time();  
$css_files = array(
    
'large',
    
'larger',
    
'med',
    
'reg',
    
'textonly'
);

if (isset(
$_GET['textsize']) AND in_array($_GET['textsize'], $css_files))
{
    
$selectedstyle "{$_GET['textsize']}.css";
    
setcookie('text'$_GET['textsize'], $inTwoMonths);
}
else if (isset(
$_COOKIE['text']) AND in_array($_COOKIE['text'], $css_files))
{
    
$selectedstyle "{$_COOKIE['text']}.css";
}
else
{
    
$selectedstyle 'reg.css';


Last edited by Nico; 12-12-07 at 10:24 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #4 (permalink)  
Old 12-12-07, 10:52 AM
coolmark18's Avatar
coolmark18 coolmark18 is offline
Newbie Coder
 
Join Date: Oct 2005
Posts: 94
Thanks: 0
Thanked 0 Times in 0 Posts
I use the confirmsize.php page to allow for a check of the cookie so that problem is avoided.

Although, Niko, your code worked fine in Firefox, again it doesnt work in IE. I've checked cookies are enabled and it says yes.

Any other suggestions?

Mark
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #5 (permalink)  
Old 12-12-07, 10:54 AM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,074
Thanks: 11
Thanked 88 Times in 83 Posts
What output does this give you:
PHP Code:

print_r($_COOKIE); 

??

And what exactly happens in IE? Does it always give you the normal style sheet?

EDIT:

4000th post.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #6 (permalink)  
Old 12-12-07, 11:08 AM
coolmark18's Avatar
coolmark18 coolmark18 is offline
Newbie Coder
 
Join Date: Oct 2005
Posts: 94
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by Nico View Post
What output does this give you:
PHP Code:

print_r($_COOKIE); 

??

And what exactly happens in IE? Does it always give you the normal style sheet?

EDIT:

4000th post.
Congrats on your post:

This is all I get:
Quote:
Array ( )
In FireFox I get
Quote:
Array ( [__utma] => 208832594.1073000590.1197331028.1197471838.1197475 135.6 [__utmz] => 208832594.1197475135.6.6.utmccn=(referral)|utmcsr= domain.com|utmcct=/text|utmcmd=referral [__utmc] => 208832594 [__utmb] => 208832594 [text] => larger )
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Cookie Problem tommyc325 PHP 2 12-14-06 01:31 PM
Cookie problem, not being set. stormshadow PHP 5 12-10-06 04:55 PM
Cookie problem Tempestshade PHP 5 06-14-05 06:37 AM
Setting a cooke (time it expires) mcrob PHP 4 04-27-05 01:13 PM
cookie problem darkcarnival PHP 11 12-27-03 07:17 PM


All times are GMT -5. The time now is 09:49 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.