php session tracking and MySQL?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • marslee@hotmail.com

    php session tracking and MySQL?

    I am a php newbie. I would like to count how many times a user visit a
    webpage.
    I know session tracking should be used, but where i put the code? Is it
    inside the html that the user visit?

    session_start() ;
    if (!IsSet($page_n umber))
    $page_number = 1;
    print("You have now visited $page_number");
    print(" of pages <br />");
    $page_number++;
    $session_regist er("page_number ");

    Also, i want to record the number of time a user visit a page and store
    it in MySQL. I know how to do it using "form action and submit" way,
    but
    have no clue of doing it with session tracking .

  • Steven Stern

    #2
    Re: php session tracking and MySQL?

    On 30 May 2005 09:34:29 -0700 (more or less), marslee@hotmail .com wrote:
    [color=blue]
    >I am a php newbie. I would like to count how many times a user visit a
    >webpage.
    >I know session tracking should be used, but where i put the code? Is it
    >inside the html that the user visit?
    >
    >session_start( );
    > if (!IsSet($page_n umber))
    > $page_number = 1;
    > print("You have now visited $page_number");
    > print(" of pages <br />");
    > $page_number++;
    > $session_regist er("page_number ");
    >
    >Also, i want to record the number of time a user visit a page and store
    >it in MySQL. I know how to do it using "form action and submit" way,
    >but
    >have no clue of doing it with session tracking .[/color]

    You can't do what you want with session cookes. You'll need to create a
    permanent (or at least long duration) cookie for a visitor.

    Something like:

    // look for an existing cookie for this site

    if (isset($_COOKIE['$thispage'])) { // if found, increment the count in
    the database
    update_db($user _code,$thispage );
    }

    // set a cookie (or extend the life of the current one

    setcookie($aUni queID,$thispage ,time()+60*60*2 4*30);

    Comment

    Working...