Forum Moderators: coopster

Message Too Old, No Replies

a problem about logging in and out

         

4ior

12:49 pm on Apr 24, 2006 (gmt 0)

10+ Year Member



Hi,
i have problem that when i login it redirects me to my main page and there i have a function islogged() if the function returns true then the member is logged in if it returns false then the member is not logged in.
The problem is that when i return to the page after being redirected it doesn't log me in automaticly. i have to refresh the page to log in.

Parts of the code:
functions.php

function isLogged() {
return (defined('USERID'));
}

login.php

header("Location: index.php");

index.php

if(!isLogged()) { echo "not logged in"; }
else {
echo "logged in";
}

it echos not logged in.
and then when i refresh the page it echoes logged in.

thank you

hakre

1:02 pm on Apr 24, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



hi 4ior,

welcome to Webmasterworld. It looks like you're facing a problem with caching here: your browser does not request the current page until you refresh it manually.

things to do:

  • add a random number as a query string to your main-page to generate a new address of that page for each redirection. that way you browser has no cached copy of that page available:
    header("Location: urlofmainpage[b]?".uniqid(rand(), true)."=".uniqid(rand(), true)[/b]);

  • checkout your browsers preferences and tell it not to cache pages (always request the latest version).
  • send additional headers to the client on that page to tell it not to cache the page: [php.net...] (take a look especially at the users comments there, this problem does occur to many people)

    hope this helps,
    hakre

  • 4ior

    2:36 pm on Apr 24, 2006 (gmt 0)

    10+ Year Member



    thanks for the fast reply.

    I believe that that is not the problem.
    in functions.php
    the function islogged()
    is before session_start();
    (also the function that is defining userid is before session_start();.)

    I didn't quite understand what you said.
    Thank you.

    hakre

    3:28 pm on Apr 24, 2006 (gmt 0)

    WebmasterWorld Senior Member 10+ Year Member



    in php it is not important where the function is written down, it is important when the function is called.

    is the function called before session_start(); or afterwards?

    where is the contant userid defined?

    which php version are you using?

    4ior

    4:16 pm on Apr 24, 2006 (gmt 0)

    10+ Year Member



    ok,
    the function is called after session_start();
    the constant userid is defined in this function:
    setGlobalVars();

    it goes like this:
    function isLogged() {
    return (defined('USERID'));
    }
    session_start();
    setGlobalVars();

    and any time that i want to log in i do:

    if(!isLogged()){
    echo "error";
    }
    else{
    echo "content";
    }

    hakre

    7:11 am on Apr 25, 2006 (gmt 0)

    WebmasterWorld Senior Member 10+ Year Member



    do you know how to check your php version to post it here?

    additionally that does not seem to be a problem of the order, it looks like setGlobalVars() does not do what's intended or you face the problem with cached pages.