Professional Web Applications Themes

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

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 ...

  1. #1

    Default 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.php -- located in admin.localhost
    <?
    session_start();
    echo "id is " . session_id();
    ?>
    a href="http://admin.localhost/session_test1.php" next

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

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

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


    php.ini relevant code:

    session.save_handler = files
    session.save_path = \temp
    session.use_cookies = 1
    session.name = PHPSESSID
    session.auto_start = 0
    session.cookie_lifetime = 0
    session.cookie_path = /
    session.cookie_domain =
    session.serialize_handler = php
    session.gc_probability = 1
    session.gc_dividend = 100
    session.gc_maxlifetime = 1440
    session.bug_compat_42 = 0
    session.bug_compat_warn = 0
    session.referer_check =
    session.entropy_length = 0
    session.entropy_file =
    session.cache_expire = 180
    session.use_trans_sid = 0
    Dave Mateer Guest

  2. #2

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

    Dave,

    From php.net, the section on session functions, and the function
    "session_set_cookie_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_vars)

    ex:
    [url]www.fluidideas.com[/url]
    chat.fluidideas.com
    mypage.fluidideas.com
    [url]www.mypage.fluidideas.com[/url]
    these will all have access to the session.

    !!!BEGIN CUT!!!

    session_set_cookie_params ( time()+9999999 , "" , ".fluidideas.com" );

    if ( $HTTP_COOKIE_VARS[session_id_set] )
    { session_id( $HTTP_COOKIE_VARS[session_id_set] ); }
    session_start ();
    Function session_walker($Array)
    {
    If ( !Is_Array($Array) ) 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_id = session_id();
    setcookie("session_id_set","$user_session_id",time ()+9999999,"",
    ".fluidideas.com", "");

    session_register("user");
    session_register("password");
    session_register("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 [url]www.fluidideas.com[/url]

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

    </end anonymous genious posting>

    Dave Mateer wrote:
    > 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.php -- located in admin.localhost
    > <?
    > session_start();
    > echo "id is " . session_id();
    > ?>
    > a href="http://admin.localhost/session_test1.php" next
    >
    > a href="http://main.localhost/session_test2.php" next
    >
    > // session_test1.php -- located in admin.localhost
    > <?
    > session_start();
    > echo "id is " . session_id();
    > ?>
    >
    > // session_test2.php -- located in main.localhost
    > <?
    > session_start();
    > echo "id is " . session_id();
    > ?>
    >
    >
    > php.ini relevant code:
    >
    > session.save_handler = files
    > session.save_path = \temp
    > session.use_cookies = 1
    > session.name = PHPSESSID
    > session.auto_start = 0
    > session.cookie_lifetime = 0
    > session.cookie_path = /
    > session.cookie_domain =
    > session.serialize_handler = php
    > session.gc_probability = 1
    > session.gc_dividend = 100
    > session.gc_maxlifetime = 1440
    > session.bug_compat_42 = 0
    > session.bug_compat_warn = 0
    > session.referer_check =
    > session.entropy_length = 0
    > session.entropy_file =
    > session.cache_expire = 180
    > session.use_trans_sid = 0
    Jason Dumler Guest

  3. #3

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

    Many thanks Jason.

    Dave.
    Dave Mateer Guest

Similar Threads

  1. Mail using Localhost
    By dannyra in forum Coldfusion Server Administration
    Replies: 1
    Last Post: September 13th, 09:39 PM
  2. cna't ssh localhost
    By Eugene M. Minkovskii in forum FreeBSD
    Replies: 2
    Last Post: February 24th, 02:50 PM
  3. how to set up 'localhost' for IE?
    By shawn in forum PHP Development
    Replies: 3
    Last Post: June 11th, 01:36 PM
  4. sessions with localhost
    By Simon K in forum ASP
    Replies: 3
    Last Post: September 15th, 02:29 PM
  5. postNetText on localhost??
    By stevo_242 webforumsuser@macromedia.com in forum Macromedia Director Lingo
    Replies: 3
    Last Post: August 21st, 02:05 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139