Jump to content


Photo

Session works in Firefox, but not in Internet Explorer


  • Please log in to reply
16 replies to this topic

#1 phpasaurusREX

phpasaurusREX
  • New Members
  • Pip
  • Newbie
  • 9 posts

Posted 27 May 2006 - 03:54 PM

The goal is to design an W3C and Section 508 standards-compliant web site that gives the user the ability to customize the look and feel by selecting options from a drop-down list. I am a front-end designer, fluent in CSS and XHTML, but I have no experience with forms or back-end scripting. This is where I need help.

Here is the link to a demo of what I am trying to do: [a href=\"http://www.designx.biz/test\" target=\"_blank\"]http://www.designx.biz/test[/a]

If you open the above link in Firefox and start clicking through the links, then you should see how the site "remembers" your preferences as you go along. You can customize the style of the site to your liking, which should prove for a more enjoyable user experience. If you open the above link in Internet Explorer, however, then it does not change the styles when you click on the links. This is a problem. I chose to use standard hyperlinks for this demo, though I would like to make it work with XHTML drop-down form menus once I get the PHP working.

Here is a link to a ZIP file containing all the files in the above demo: [a href=\"http://www.designx.biz/test/test.zip\" target=\"_blank\"]http://www.designx.biz/test/test.zip[/a]

I am willing to keep an open mind, so feel free to suggest alternative means to meet my goal. The thought of storing the style preferences in cookies also crossed my mind, because it would be cool for the site to "remember" your style preferences if you re-visit the site after several reboots and a few days time. I am sure you all can see where I am going with this, so I hope you can help me!

Here is the code from switcher_background.php:

<?php 
session_start();
if ( ! session_is_registered("background") ) {
    session_register("background");
    $_SESSION['background'] = 'background_black';
    $background = $_SESSION['background'];
    } 
else {
    $background = $_SESSION['background'];
    }
if ( ! session_is_registered("color") ) {
    session_register("color");
    $_SESSION['color'] = 'color_yellow';
    $color = $_SESSION['color'];
    } 
else {
    $color = $_SESSION['color'];
    }
if ( ! session_is_registered("size") ) {
    session_register("size");
    $_SESSION['size'] = 'size_small';
    $size = $_SESSION['size'];
    } 
else {
    $size = $_SESSION['size'];
    }
if ( ! session_is_registered("font") ) {
    session_register("font");
    $_SESSION['font'] = 'font_verdana';
    $font = $_SESSION['font'];
    } 
else {
    $font = $_SESSION['font'];
    }
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>StyleSheet Switcher</title>
<link rel="stylesheet" type="text/css" href="screen.css">
<link rel="alternative stylesheet" type="text/css" href="<?php echo $background ?>.css" title="User Defined Style">
<link rel="alternative stylesheet" type="text/css" href="<?php echo $alignment ?>.css" title="User Defined Style">
<link rel="alternative stylesheet" type="text/css" href="<?php echo $color ?>.css" title="User Defined Style">
<link rel="alternative stylesheet" type="text/css" href="<?php echo $size ?>.css" title="User Defined Style">
<link rel="alternative stylesheet" type="text/css" href="<?php echo $font ?>.css" title="User Defined Style">
</head>
<body>
Change Background Color<br>
<a href="switcher_background.php?background=background_black">Black</a><br>
<a href="switcher_background.php?background=background_red">Red</a><br>
<a href="switcher_background.php?background=background_green">Green</a><br>
<a href="switcher_background.php?background=background_blue">Blue</a><br>
<br>Change Alignment<br>
<a href="switcher_alignment.php?alignment=alignment_left">Left</a><br>
<a href="switcher_alignment.php?alignment=alignment_center">Center</a><br>
<a href="switcher_alignment.php?alignment=alignment_right">Right</a><br>
<br>Change Font Size<br>
<a href="switcher_size.php?size=size_small">Small</a><br>
<a href="switcher_size.php?size=size_medium">Medium</a><br>
<a href="switcher_size.php?size=size_large">Large</a><br>
<br>Change Font Color<br>
<a href="switcher_color.php?color=color_yellow">Yellow</a><br>
<a href="switcher_color.php?color=color_white">White</a><br>
<br>Change Font<br>
<a href="switcher_font.php?font=font_verdana">Verdana</a><br>
<a href="switcher_font.php?font=font_georgia">Georgia</a>
</body> 
</html>

Here is the code from switcher_background.php: (there are individual switchers for each style change)

<?php
session_start(); 
if ( ! session_is_registered("background") ) {
    session_register("background");
    } 
$_SESSION['background'] = $_GET['background']; 
header("Location: ".$_SERVER['HTTP_REFERER'] );
?>


#2 bobleny

bobleny
  • Members
  • PipPipPip
  • Advanced Member
  • 429 posts

Posted 27 May 2006 - 04:00 PM

<?php
session_start();
header("Cache-control: private");

Are you useing the header(); after the session_start(); ?
-- www.firemelt.net --
First do me a favor and read this: JavaScript is NOT Java - Then read this: www.php.net - When your done with that, read this Topic
After that, floors open. I and anyone else will be MORE than happy to answer YOUR query! [Topic Solved]
Cheer up, the worst has yet to come...

#3 phpasaurusREX

phpasaurusREX
  • New Members
  • Pip
  • Newbie
  • 9 posts

Posted 27 May 2006 - 04:10 PM

[!--quoteo(post=377594:date=May 27 2006, 12:00 PM:name=Bob Leny)--][div class=\'quotetop\']QUOTE(Bob Leny @ May 27 2006, 12:00 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
<?php
session_start();
header("Cache-control: private");

Are you useing the header(); after the session_start(); ?
[/quote]
I updated my original post to include the PHP code, let me know if this answers your question.


#4 toplay

toplay
  • Staff Alumni
  • Advanced Member
  • 973 posts

Posted 27 May 2006 - 04:15 PM

Don't use session_register() and $_SESSION. Read the third caution box here:
[a href=\"http://us2.php.net/manual/en/function.session-register.php\" target=\"_blank\"]http://us2.php.net/manual/en/function.session-register.php[/a]

Just use $_SESSION.

Take a look at our session troubleshooting guide:
[a href=\"http://www.phpfreaks.com/forums/index.php?showtopic=31047&view=findpost&p=157705\" target=\"_blank\"]http://www.phpfreaks.com/forums/index.php?...ndpost&p=157705[/a]

#5 bobleny

bobleny
  • Members
  • PipPipPip
  • Advanced Member
  • 429 posts

Posted 27 May 2006 - 04:16 PM

Ok yeah, header("Cache-control: private"); is the fix to IE so place header("Cache-control: private"); imidetlly after the session_start(); on evrey page you have your sessions

Like this

<?php
session_start();
header("Cache-control: private");
if ( ! session_is_registered("background") ) {
-- www.firemelt.net --
First do me a favor and read this: JavaScript is NOT Java - Then read this: www.php.net - When your done with that, read this Topic
After that, floors open. I and anyone else will be MORE than happy to answer YOUR query! [Topic Solved]
Cheer up, the worst has yet to come...

#6 phpasaurusREX

phpasaurusREX
  • New Members
  • Pip
  • Newbie
  • 9 posts

Posted 27 May 2006 - 04:35 PM

[!--quoteo(post=377603:date=May 27 2006, 12:15 PM:name=toplay)--][div class=\'quotetop\']QUOTE(toplay @ May 27 2006, 12:15 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
Don't use session_register() and $_SESSION. Read the third caution box here:
[a href=\"http://us2.php.net/manual/en/function.session-register.php\" target=\"_blank\"]http://us2.php.net/manual/en/function.session-register.php[/a]

Just use $_SESSION.
[/quote]
If I take out the session_register(), then how will it know which session to start? For each style change (background, font, etc.) I need to use an alterative style sheet. So, if someone clicks on "red" as a background color, then the PHP needs to replace the file name in the HTML so the red style sheet is loaded.

[!--quoteo(post=377604:date=May 27 2006, 12:16 PM:name=Bob Leny)--][div class=\'quotetop\']QUOTE(Bob Leny @ May 27 2006, 12:16 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
Ok yeah, header("Cache-control: private"); is the fix to IE so place header("Cache-control: private"); imidetlly after the session_start(); on evrey page you have your sessions

Like this

<?php
session_start();
header("Cache-control: private");
if ( ! session_is_registered("background") ) {
[/quote]
I tried putting header("Cache-control: private"); on every page and it still does not work in IE.

#7 bobleny

bobleny
  • Members
  • PipPipPip
  • Advanced Member
  • 429 posts

Posted 27 May 2006 - 04:50 PM

I think top play might be right.

Try chageing this...
if ( ! session_is_registered("background") ) {
    session_register("background");
    $_SESSION['background'] = 'background_black';
    $background = $_SESSION['background'];
    }
else {
    $background = $_SESSION['background'];
    }

To this...
if (isset($_SESSION["background"]) ) {
    $_SESSION['background'] = 'background_black';
    $background = $_SESSION['background'];
    }
else {
    $background = $_SESSION['background'];
    }

edit: I chaged it fro ! to the isset function which will check to see if the varieble exists.
lol sorry I think thats backwords!

Use this instead
if (isset($_SESSION["background"]))
{
    $background = $_SESSION['background'];
}
else
{
    $_SESSION['background'] = 'background_black';
    $background = $_SESSION['background'];
}

-- www.firemelt.net --
First do me a favor and read this: JavaScript is NOT Java - Then read this: www.php.net - When your done with that, read this Topic
After that, floors open. I and anyone else will be MORE than happy to answer YOUR query! [Topic Solved]
Cheer up, the worst has yet to come...

#8 phpasaurusREX

phpasaurusREX
  • New Members
  • Pip
  • Newbie
  • 9 posts

Posted 27 May 2006 - 05:04 PM

[!--quoteo(post=377614:date=May 27 2006, 12:50 PM:name=Bob Leny)--][div class=\'quotetop\']QUOTE(Bob Leny @ May 27 2006, 12:50 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
I think top play might be right.

Try chageing this...
if ( ! session_is_registered("background") ) {
    session_register("background");
    $_SESSION['background'] = 'background_black';
    $background = $_SESSION['background'];
    }
else {
    $background = $_SESSION['background'];
    }

To this...
if (isset($_SESSION["background"]) ) {
    $_SESSION['background'] = 'background_black';
    $background = $_SESSION['background'];
    }
else {
    $background = $_SESSION['background'];
    }

edit: I chaged it fro ! to the isset function which will check to see if the varieble exists
[/quote]

When I make these changes to the index.php file, it does not work in IE or Firefox.

#9 bobleny

bobleny
  • Members
  • PipPipPip
  • Advanced Member
  • 429 posts

Posted 27 May 2006 - 05:08 PM

I think I might know a much easier way to do this! could I see a coulple of your style sheets?
-- www.firemelt.net --
First do me a favor and read this: JavaScript is NOT Java - Then read this: www.php.net - When your done with that, read this Topic
After that, floors open. I and anyone else will be MORE than happy to answer YOUR query! [Topic Solved]
Cheer up, the worst has yet to come...

#10 phpasaurusREX

phpasaurusREX
  • New Members
  • Pip
  • Newbie
  • 9 posts

Posted 27 May 2006 - 05:10 PM

[!--quoteo(post=377624:date=May 27 2006, 01:08 PM:name=Bob Leny)--][div class=\'quotetop\']QUOTE(Bob Leny @ May 27 2006, 01:08 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
I think I might know a much easier way to do this! could I see a coulple of your style sheets?
[/quote]

Here is a link to a ZIP file containing all the files: [a href=\"http://www.designx.biz/test/test.zip\" target=\"_blank\"]http://www.designx.biz/test/test.zip[/a]

#11 bobleny

bobleny
  • Members
  • PipPipPip
  • Advanced Member
  • 429 posts

Posted 27 May 2006 - 05:23 PM

Very interesting, you have more than what I thought. If you don’t mind, id like to run a couple of tests to check a couple of things. This will take me an hour or 2 though.

-- www.firemelt.net --
First do me a favor and read this: JavaScript is NOT Java - Then read this: www.php.net - When your done with that, read this Topic
After that, floors open. I and anyone else will be MORE than happy to answer YOUR query! [Topic Solved]
Cheer up, the worst has yet to come...

#12 phpasaurusREX

phpasaurusREX
  • New Members
  • Pip
  • Newbie
  • 9 posts

Posted 27 May 2006 - 05:26 PM

[!--quoteo(post=377630:date=May 27 2006, 01:23 PM:name=Bob Leny)--][div class=\'quotetop\']QUOTE(Bob Leny @ May 27 2006, 01:23 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
Very interesting, you have more than what I thought. If you don’t mind, id like to run a couple of tests to check a couple of things. This will take me an hour or 2 though.
[/quote]

Sure thing, I really appreciate it. I do not know what I am doing with PHP, so you might be able to find a much more simplified way of doing this.

#13 448191

448191
  • Staff Alumni
  • Advanced Member
  • 3,545 posts
  • LocationNetherlands

Posted 27 May 2006 - 05:33 PM

Pardon, but I tested your code (though very sloppy and way too long for it's intended pupose) and it works fine over here on IE, FF ánd Opera. I don't see the problem... Maybe you have FF set not to accept any cookies?

#14 phpasaurusREX

phpasaurusREX
  • New Members
  • Pip
  • Newbie
  • 9 posts

Posted 27 May 2006 - 07:07 PM

[!--quoteo(post=377632:date=May 27 2006, 01:33 PM:name=448191)--][div class=\'quotetop\']QUOTE(448191 @ May 27 2006, 01:33 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
Pardon, but I tested your code (though very sloppy and way too long for it's intended pupose) and it works fine over here on IE, FF ánd Opera. I don't see the problem... Maybe you have FF set not to accept any cookies?
[/quote]

Ok, like I said this is my first time using PHP and I don't know what I am doing. I would appreciate suggestions on how to clean the code up and make it shorter, as opposed to just stating its sloppy and too long. By the way, [a href=\"http://www.designx.biz/test\" target=\"_blank\"]http://www.designx.biz/test[/a] works fine in FF. IE is the problematic browser. I have cookies enabled and default settings in both browsers. Could you double check [a href=\"http://www.designx.biz/test\" target=\"_blank\"]http://www.designx.biz/test[/a] in IE and make sure you can switch styles?

#15 bobleny

bobleny
  • Members
  • PipPipPip
  • Advanced Member
  • 429 posts

Posted 27 May 2006 - 08:00 PM

Well I tried it on IE and it didnt work and I have cookies on. Im thinking sessions arnt cookies. maybe im wrong about that...
-- www.firemelt.net --
First do me a favor and read this: JavaScript is NOT Java - Then read this: www.php.net - When your done with that, read this Topic
After that, floors open. I and anyone else will be MORE than happy to answer YOUR query! [Topic Solved]
Cheer up, the worst has yet to come...

#16 448191

448191
  • Staff Alumni
  • Advanced Member
  • 3,545 posts
  • LocationNetherlands

Posted 28 May 2006 - 07:04 AM

When you debug, isolate.

To test if your session script worked, I tesed only the php code! So you problem is NOT with the php code.

<?php 
session_start();
if (!session_is_registered('background') ) {
    session_register('background');
    $_SESSION['background'] = 'background_black';
    $background = $_SESSION['background'];
} 
else {
    echo $_SESSION['background'];
}
if (!session_is_registered('color') ) {
    session_register('color');
    $_SESSION['color'] = 'color_yellow';
    $color = $_SESSION['color'];
} 
else {
    echo $_SESSION['color'];
}
if (!session_is_registered('size') ) {
    session_register('size');
    $_SESSION['size'] = 'size_small';
    $size = $_SESSION['size'];
} 
else {
    echo $_SESSION['size'];
}
if (!session_is_registered('font') ) {
    session_register('font');
    $_SESSION['font'] = 'font_verdana';
    $font = $_SESSION['font'];
} 
else {
    echo $_SESSION['font'];
}
?>

On page refresh, this code echoes: "background_blackcolor_yellowsize_smallfont_verdana" which proves sessions are working fine. Your problem lies elsewhere.

P.S. PHP session can use either 'get '(i.e. "index.php?sessionid=1f3870be274f6c49b3e31a0c6728957f") or a cookie to pass the session id across pages... Having your php.ini set to use cookies when a user has cookies disabled will cause sessions to fail, as php doesn't know which session to use.

#17 bobleny

bobleny
  • Members
  • PipPipPip
  • Advanced Member
  • 429 posts

Posted 28 May 2006 - 06:22 PM

Ok this is what you want. Sorry it took so long! I wrote out the script and I had a friend (Hes alot better at php than I! Alot!) make some adjustments and fix my mistakes and it came out real nice!!!!

Ok page 1
<?php
session_start();
header("Cache-control: private");

if (isset($_SESSION["background"]))
{
    $background = $_SESSION['background'];
}
else
{
    $_SESSION['background'] = "#000000";
    $background = $_SESSION['background'];
}

if (isset($_SESSION["text"]))
{
    $text = $_SESSION['text'];
}
else
{
    $_SESSION['text'] = "#FFFFFF";
    $text = $_SESSION['text'];
}
?>
<html>
<head>
<style type="text/css">
<?php include(".06page3.php") ?>
</style>
</head>
<body>

<form action=".06page2.php" method="post">
Change Background Color:
<select name="background">
<option value="#000000">Black</option>
<option value="#FF0000">Red</option>
<option value="#00FF00">Green</option>
<option value="#0000FF">Blue</option>
</select>
<br />
Change Text Color:
<select name="text">
<option value="#FFFFFF">White</option>
<option value="#0000FF">Blue</option>
<option value="#FF0000">Red</option>
</select>
<br />
<input type="submit" value="Change!">
</form>


</body>
</html>


Ok now page 2
<?php
session_start();
header("Cache-control: private");

$_SESSION['background'] = $_POST['background'];

$_SESSION['text'] = $_POST['text'];

echo "<META HTTP-EQUIV='Refresh' delay=.1 CONTENT= '.1; URL=.06page1.php'>"
?>


Now you could of done this in 2 pages but so that you have something like an external style sheet we put the inline styles in an external page. So use this in place of your css file.
BODY
{
background-color: <?php echo $background; ?>;
color: <?php echo $text; ?>;
}

Yeah working example at www.firemelt.net/.06page1.php Ill leave it up for a little while too
-- www.firemelt.net --
First do me a favor and read this: JavaScript is NOT Java - Then read this: www.php.net - When your done with that, read this Topic
After that, floors open. I and anyone else will be MORE than happy to answer YOUR query! [Topic Solved]
Cheer up, the worst has yet to come...




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users