Something simple!? Sessions - admin.localhost to main.localhost

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Dave Mateer

    Something simple!? Sessions - admin.localhost to main.localhost

    Hi

    Why does the following code allow me to keep the same session when in
    the same sub domain (ie admin.localhost ), yet not when I goto another
    related domain eg main.localhost?

    I would like to have the same session on the related domain. I bet
    the solution is really simple <grin>!...

    Kind Regards

    Dave.

    Using IE6. Win NT, Apache 1.3.27, PHP 4.3.2.

    php.ini file - shown at end of message (apologies for length).. is
    actually a copy of a PHP4.3.0 ini file (problem here?)

    hosts file in windows:

    127.0.0.1 localhost
    127.0.0.1 admin.localhost
    127.0.0.1 main.localhost

    httpd.conf

    setup for VirtualHosts
    eg
    ServerName admin.localhost .com


    // session_test.ph p -- located in admin.localhost
    <?
    session_start() ;
    echo "id is " . session_id();
    ?>
    a href="http://admin.localhost/session_test1.p hp" next

    a href="http://main.localhost/session_test2.p hp" next

    // session_test1.p hp -- located in admin.localhost
    <?
    session_start() ;
    echo "id is " . session_id();
    ?>

    // session_test2.p hp -- located in main.localhost
    <?
    session_start() ;
    echo "id is " . session_id();
    ?>


    php.ini relevant code:

    session.save_ha ndler = files
    session.save_pa th = \temp
    session.use_coo kies = 1
    session.name = PHPSESSID
    session.auto_st art = 0
    session.cookie_ lifetime = 0
    session.cookie_ path = /
    session.cookie_ domain =
    session.seriali ze_handler = php
    session.gc_prob ability = 1
    session.gc_divi dend = 100
    session.gc_maxl ifetime = 1440
    session.bug_com pat_42 = 0
    session.bug_com pat_warn = 0
    session.referer _check =
    session.entropy _length = 0
    session.entropy _file =
    session.cache_e xpire = 180
    session.use_tra ns_sid = 0
  • Jason Dumler

    #2
    Re: Something simple!? Sessions - admin.localhost to main.localhost

    Dave,

    From php.net, the section on session functions, and the function
    "session_set_co okie_params", it was posted by a person who just doesn't
    want to receive junk mail (it was not me). Basically you have to tell
    the browser that the domain is domain.com, not sub.domain.com. It's
    more of a client issue than a server issue.

    <begin anonymous genious stuff here>

    junkmail at fluidideas dot com
    22-Feb-2001 12:33
    ok. hope this works. first time posting

    heres a quick little snippet I came up with to pass sessions between
    lots of sub domains or c names. it also contains an array walker for
    reading and outputting the contents of the current array(in this case i
    use it for http_session_va rs)

    ex:
    Saw.com has successfully helped thousands of buyers acquire the perfect domain name. Interested in fluidideas.com? Let’s get started.

    chat.fluidideas .com
    mypage.fluidide as.com

    these will all have access to the session.

    !!!BEGIN CUT!!!

    session_set_coo kie_params ( time()+9999999 , "" , ".fluidideas.co m" );

    if ( $HTTP_COOKIE_VA RS[session_id_set] )
    { session_id( $HTTP_COOKIE_VA RS[session_id_set] ); }
    session_start ();
    Function session_walker( $Array)
    {
    If ( !Is_Array($Arra y) ) Return $Array;
    Reset($Array);
    While( List( $Key, $Value ) = Each( $Array ) )
    {
    If ( Is_Array( $Array[ $Key ] ) )
    {
    $Array[ $Key ] = session_walker( $Array[ $Key ] );
    }
    Else
    {
    echo "key -> " . $Key . "
    \n";
    echo "value -> " . $Value . "
    \n";
    }
    }
    Return $Array;
    }

    !!!END CUT FOR SESSION INCLUDE!!!
    !!!BEGIN CUT!!!

    $user_session_i d = session_id();
    setcookie("sess ion_id_set","$u ser_session_id" ,time()+9999999 ,"",
    ".fluidideas.co m", "");

    session_registe r("user");
    session_registe r("password") ;
    session_registe r("email");

    !!!END CUT FOR LOGIN!!!

    now this example will allow the session to carry the data from sub
    domain to sub domain and it only has one flaw that i've noticed. NS 4.7
    is the only browser I've seen this in (also use mozilla .8 and IE5.5)
    but if the domain doesnt contain a c name the sessions wont pass.

    ex: fluidideas.com not www.fluidideas.com

    If someone can come up with a fix to this please email me. Thanks

    </end anonymous genious posting>

    Dave Mateer wrote:[color=blue]
    > Hi
    >
    > Why does the following code allow me to keep the same session when in
    > the same sub domain (ie admin.localhost ), yet not when I goto another
    > related domain eg main.localhost?
    >
    > I would like to have the same session on the related domain. I bet
    > the solution is really simple <grin>!...
    >
    > Kind Regards
    >
    > Dave.
    >
    > Using IE6. Win NT, Apache 1.3.27, PHP 4.3.2.
    >
    > php.ini file - shown at end of message (apologies for length).. is
    > actually a copy of a PHP4.3.0 ini file (problem here?)
    >
    > hosts file in windows:
    >
    > 127.0.0.1 localhost
    > 127.0.0.1 admin.localhost
    > 127.0.0.1 main.localhost
    >
    > httpd.conf
    >
    > setup for VirtualHosts
    > eg
    > ServerName admin.localhost .com
    >
    >
    > // session_test.ph p -- located in admin.localhost
    > <?
    > session_start() ;
    > echo "id is " . session_id();
    > ?>
    > a href="http://admin.localhost/session_test1.p hp" next
    >
    > a href="http://main.localhost/session_test2.p hp" next
    >
    > // session_test1.p hp -- located in admin.localhost
    > <?
    > session_start() ;
    > echo "id is " . session_id();
    > ?>
    >
    > // session_test2.p hp -- located in main.localhost
    > <?
    > session_start() ;
    > echo "id is " . session_id();
    > ?>
    >
    >
    > php.ini relevant code:
    >
    > session.save_ha ndler = files
    > session.save_pa th = \temp
    > session.use_coo kies = 1
    > session.name = PHPSESSID
    > session.auto_st art = 0
    > session.cookie_ lifetime = 0
    > session.cookie_ path = /
    > session.cookie_ domain =
    > session.seriali ze_handler = php
    > session.gc_prob ability = 1
    > session.gc_divi dend = 100
    > session.gc_maxl ifetime = 1440
    > session.bug_com pat_42 = 0
    > session.bug_com pat_warn = 0
    > session.referer _check =
    > session.entropy _length = 0
    > session.entropy _file =
    > session.cache_e xpire = 180
    > session.use_tra ns_sid = 0[/color]

    Comment

    • Dave Mateer

      #3
      Re: Something simple!? Sessions - admin.localhost to main.localhost

      Many thanks Jason.

      Dave.

      Comment

      Working...