sessions and domain names

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

    sessions and domain names

    Hi all. I've got an app that dumps a user id into a session after
    successful login. the login page is http://www.mydomain.com/login.php.

    If the user visits pages on my site without the www (i.e.,
    http://mydomain.com/foo.php), the session works fine and login state is
    maintained.

    If he visits http://www.mydomain.com/foo.php, the app drops the
    logged-in state.

    Any idea how to fix this? I'm running php 4.4.1 w/ linux apache.

  • Tom

    #2
    Re: sessions and domain names

    I confess I wasn't aware of this problem, but I've never encountered
    it. In addition to configuring your server to redirect to one or the
    other, you could also try this:

    I define the base url as a constant at the beginning of my scripts:

    define('MY_BASE _URL', 'http://www.mydomain.co m/');

    or, if you want to get more dynamic:

    define('MY_BASE _URL', 'http://' . $_SERVER['HTTP_HOST'] . '/');

    Then whenever you include a link on your page, just use:

    <?php echo MY_BASE_URL . 'path/to/file.php'; ?>

    Tom



    On Oct 26, 4:27 pm, "magic_hat60622 " <magic_hat60... @yahoo.comwrote :
    Hi all. I've got an app that dumps a user id into a session after
    successful login. the login page ishttp://www.mydomain.co m/login.php.
    >
    If the user visits pages on my site without the www (i.e.,http://mydomain.com/foo.php), the session works fine and login state is
    maintained.
    >
    If he visitshttp://www.mydomain.co m/foo.php, the app drops the
    logged-in state.
    >
    Any idea how to fix this? I'm running php 4.4.1 w/ linux apache.

    Comment

    Working...