Web Analytics Made Easy -
StatCounter Session Help - CodingForum

Announcement

Collapse
No announcement yet.

Session Help

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Session Help

    For some reason, my cookies don't work with IE.... so I resorted to sessions. I can't get them to work, though.

    Here's the breakdown of my script. First, the user enters their user/pass, and then the script detects which browser they are using. This works fine. The script redirects them to the session set page, and then that page redirects them to an agreement. After they agree to my terms, they are redirected to my index page (which is a chat).

    Somewhere in between there, the session isn't working.

    Here's my code:

    Session Setter:
    PHP Code:
    <?
    //grabs the style of the skin the user is using
    $style $_GET['style'] or die("COULDNT LOAD STYLE");

    //grabs the name from the previous page
    $name $_GET['name'];

    //sets the session to be recalled later
    session_start();

    $_SESSION['name'] = $name;
    $_SESSION['logged_in'] = "YES";

    //goes to the agreement page with an alert and the saved style
    header("Location: agreement.php?style=".$style."&alert=session");
    ?>
    Index page:
    PHP Code:
    <?
    session_start
    ();

    //grabs the style of the skin the user is using
    $style $_GET['style'] or die("COULDNT LOAD STYLE");

    //sets various color variables based on the style
    if ($style == "lite") {
        
    $style_color "#DEE3E7";
        
    $style_font "#000000";
        
    $style_link "#000000";
    } elseif (
    $style == "onyx") {
        
    $style_color "#2B2B2B";
        
    $style_font "#D0D0D0";
        
    $style_link "#FFFFFF";
    } else {
        die(
    "THAT STYLE DOESN'T EXIST");  //if the user inputs an invalid style
    }
    //sets the various visual options based on the style used below
    ?>
    <body bgcolor="<? echo $style_color?>" link="<? echo $style_link?>" vlink="<? echo $style_link?>" alink="<? echo $style_link?>">
    <font face="Verdana" size="1" color="<? echo $style_font?>">
    <?
    //checks to see if it can include the connection settings
    if([email protected]file_exists('connect.php')) {
       die(
    "Couldn't load the connection settings.  Seek an Administrator.");
    } else {
       require_once(
    "connect.php");
    }
    //checks to make sure you've logged in
    if (isset($_COOKIE['msgbox_name']) == TRUE) {
        @
    $name $_COOKIE['msgbox_name'];
        require_once(
    "chat_data.php");
        echo 
    "<hr>";
        require_once(
    "chat_forms.php");
    } else if (
    $_SESSION['logged_in'] == "YES") {   // this line is giving me trouble it would seem
        
    echo "session detected!";
    } else { 
    //if the user hasn't logged in yet...
        
    require_once("reg.php");
    }

    mysql_close();  // close the db connection
    ?>
    It's probably something totally stupid I'm missing, so pardon me if it is :P

  • #2
    For a session to work the user has to keep his session id which must be available on all the pages. Most common is through cookies and the query string. If cookies don't work for you it is possible that the session id doesn't get to the page you want (there is an option in PHP session to use only cookies). I would suggest you to fix the cookie problem first or make sure you propagate the sid via the query string.
    I'm not sure if this was any help, but I hope it didn't make you stupider.

    Experience is something you get just after you really need it.
    PHP Installation Guide Feedback welcome.

    Comment


    • #3
      always the first thing to check - are you using session_start(); on every page that sets or accesses session data?
      http://www.hazelryan.co.uk

      Comment


      • #4
        Originally posted by marek_mar View Post
        For a session to work the user has to keep his session id which must be available on all the pages. Most common is through cookies and the query string. If cookies don't work for you it is possible that the session id doesn't get to the page you want (there is an option in PHP session to use only cookies). I would suggest you to fix the cookie problem first or make sure you propagate the sid via the query string.
        Well, my cookies problem has something to do with security... If IE has "Accept All Cookies" enabled, everything works, but without that on, the cookies are "rejected". How can I fix that?

        (If you don't mind explaining, what are query strings and sids? (session ids?))

        Edit: Yes, I've got session_start(); at the top of both pages.

        Comment


        • #5
          You cannot really "fix" it. It'\s the user's choice to not accept cookies. You can tell your user that they need to enable cookies. Most users don't accept cookies from different pages than the one they requested - the same domain. You could also try changing the default session name (PHPSESSID) as the cookie might get overwritten (quite rare).
          Originally posted by Drevin View Post
          (If you don't mind explaining, what are query strings and sids? (session ids?))
          Query strings are the part of the URL after the "?" for example: "do=newreply&p=490446"
          If you have session.use_trans_sid set to 1 (php.ini setting) The sid will be atomically added to all URLs.
          Yes sid is short for "session id(entifier)".
          I'm not sure if this was any help, but I hope it didn't make you stupider.

          Experience is something you get just after you really need it.
          PHP Installation Guide Feedback welcome.

          Comment

          Working...
          X