Page 1 of 2 12 LastLast
Results 1 to 15 of 18
  1. #1
    Join Date
    Apr 2004
    Location
    Canada
    Posts
    57

    Unanswered: Simply Count Visits and Date of Visit

    Hi there!

    I am a beginner but I successfully have set up a Flash-PHP-MySQL login process which functions perfectly.

    I want to know what I must add to my PHP Script in order to:
    1 - Add 1 to an appropriate column in the row corresponding to the visitor each time the visitor loggins and...
    2 - Insert the date of this visit which replaces, of course, the date of the preceeding visit.

    I know of course how to insert new columns to my table and I also know how to pass variables from Flash (MX not MX2004) to PHP.

    If needed, I can post here the PHP Script I use.

    Many thanks in advance for your help!
    Best regards.

  2. #2
    Join Date
    Jan 2004
    Location
    India
    Posts
    168
    I think you want to track the users login. Like the no. of times he loged in and the time of last login. For this you just have to run an update query which will update the table where the users login is stored.
    u have can run this query just after the user get authenticated by mysql.

    If you still have doubt then plz copy the code.

    Regards
    Rajesh

  3. #3
    Join Date
    Apr 2004
    Location
    Canada
    Posts
    57
    Very kind from you to reply to my posting.

    I think you have a good understanding of my goals.
    However, in order to save time and multiple postings, here are some precisions:

    User registration/logging uses from a Flash file three PHP Scripts (which you can download, virus free of course!, at <http://www.germaris.com/files.zip>).
    One is for connecting, the other for the functions and the third for operating.

    What I really want?
    Each time a registered User logs in, it triggers automatically via the script 'user' an incremental update of 1 of its row in the appropriate column of the table (to be created) nammed for example 'hits'. It also triggers an automatic update of its row in another column (also to be created) and nammed for example 'lastVisit'.
    Well, there it is...

    If you need more explanations or informations, just tell me!

    Best regards,

    Gerard

  4. #4
    Join Date
    Jan 2004
    Location
    India
    Posts
    168
    Hi
    Give me 1-2 days of time I would surly give you a solution.
    I have taken the files. Now let me check it. I am little buzy nowadays.

    Regards
    Rajesh

  5. #5
    Join Date
    Apr 2004
    Location
    Canada
    Posts
    57
    Please do.
    Regards.
    Gerard

  6. #6
    Join Date
    Jan 2004
    Location
    India
    Posts
    168
    Where would you like to store the information of user log. you have not given any table stucture about this. i think you have to create one table in which you can store the username, last login and the hits of the user. You have to be clear that do u want to stroe each hit of the user of you want only one hit for a day. Or one hit for a session.
    Based on this you have to prepare the script and then and insert statement in the registration page where the last login and the hit will be null.
    Another query will be an update query that can be your login fuction or the page that calls the login fuction, once the function returns a true value update the table with the latest value.

    Hope you got the idea.
    If you have any more doubts let me know.

    Regards
    Rajesh

  7. #7
    Join Date
    Apr 2004
    Location
    Canada
    Posts
    57
    Hi Rajesh,

    Sorry but, if (as I invited you to) you have downloaded the files (<http://www.germaris.com/files.zip>) there is in the archive a file nammed 'users.sql' which gives you the table structure. I am able, following the solution you'll provide, to add the appropriate columns.

    I want to store each hit (number of hits will be high and because of the weight of the file I want to have an eye on the bandwith) for each user.

    About the date, each hit will update the date with the hour-minute-second precision (???) if there are multiple hits on the same day, decision will be yours as I'll follow your advices.

    The solution I need is an update query which I ask you to write and include in the script nammed 'user.php' within the login function.

    When this problem will be solved, I think I'll ask you to rewrite the 'function valid_email($email)' located in the file nammed 'functions.php' and which is disabled because it is not convenient for reasons I'll explain later.
    This new question will not be urgent and will be treated as a "bonus" only if you have some free time to dedicate to it ... :-)))

    Thank you for the interest you have in my problems!

    Best regards,

    Gerard

  8. #8
    Join Date
    Jan 2004
    Location
    India
    Posts
    168
    I have gone through the user.sql, it has only one table stucture and that is users Table, which does not have the fields for the logs. So heres what we would do.
    We will create a table like userlog. the fileds would be userid, hit (will be incremented by adding one to it when user logs in) and a time stamp. The time stamp would be better as it will store the exact time with hours & mins.
    I am attaching (http://www.rajeshrr.com/beta/test/files.zip) the two files user.php and user.sql. I have added the update code in the user.php and add the create syntax for userlogs table.
    Download it and check it. you may have to do little corrections (sometimes). As I have done this in a hurry.

    Give me the feedback for this.. tell me is this what you want.
    Regards
    Rajesh

  9. #9
    Join Date
    Apr 2004
    Location
    Canada
    Posts
    57
    Hi Rajesh,

    It's 01.40AM here in Canada...
    I got your files and I thank you very much for the job you have done.
    I haven't tested it yet.

    I prefer not to have another table for the hits because I want to have in a glimpse the number of hits right beside the identification of each user.

    I propose to you the PHP Script and a modified users Table structure at <http://www.germaris.com/gerard.zip>.
    Just open and verify them and tell me if you think it will work...

    I'll test the new files at 06.00AM EDT in Canada.

    Again, thanks for the time !!!

    Best regards,

    Gerard

    PS: It's now 10.20PM EDT in Canada. I tried your script and with your table... It doesn't work... :-(
    Last edited by Germaris; 06-25-04 at 23:18.

  10. #10
    Join Date
    Apr 2004
    Location
    Canada
    Posts
    57
    Hi Rajesh,

    I am so surprised of your silence...
    Anyway, if you agree to continue to help me, here is what I tried to do with my problem.

    I insist to continue using one and only one table for User Login and Counting User hits.

    Here below are the table structure and the PHP code.

    If you have any question, feel free to ask...

    Best regards,

    Gerard

    PS: I display only the counting function of the full PHP script...



    CREATE TABLE users (
    userID int(20) unsigned NOT NULL auto_increment,
    userName varchar(15) NOT NULL default '0',
    userPassword varchar(32) NOT NULL default '0',
    userMail varchar(255) NOT NULL default '',
    userQuestion varchar(255) NOT NULL default '',
    userAnswer varchar(255) NOT NULL default '',
    userHit int(11) NOT NULL default '',
    logTime int(11) NOT NULL default '',
    name varchar(35) NOT NULL default '',
    first varchar(35) NOT NULL default '',
    school varchar(255) NOT NULL default '',
    promo varchar(4) NOT NULL default '',
    PRIMARY KEY (userID),
    UNIQUE KEY userMail (userMail),
    UNIQUE KEY userName (userName)
    ) TYPE=MyISAM PACK_KEYS=0;



    Code:
    <?php
    function counting($username)
    {
    	GLOBAL $db,$table;
    	$username = trim($username);
    	$username = $obj->userName
    	$sql = "SELECT * FROM $table WHERE userName = '$username'"
    	$result = mysql_query($sql);
    	if($result)
    	{
    		$row = mysql_fetch_object($result);
    		$userhit = $row->userHit
    		$query = "UPDATE $table SET userHit='".$userhit+1."', logTime='time()' WHERE userName='$username'";
    		mysql_query($query) or die(mysql_error());
    	}
    	else
    	{
    		$query1 = "INSERT INTO $table VALUES ('1','time()')";
    		mysql_query($query) or die(mysql_error());
    	}
    	return mysql_num_rows($query);
    }
    ?>
    Last edited by Germaris; 06-27-04 at 11:38.

  11. #11
    Join Date
    Jan 2004
    Location
    India
    Posts
    168
    It was the weekend for us... and I was out of station.. I went for an outing. I will check thought the code and as you insist i will we will fix with one table. I will get back to you soon.

    Regards
    Rajesh

  12. #12
    Join Date
    Apr 2004
    Location
    Canada
    Posts
    57
    Thank you very very very much Rajesh. ;-)))
    Very kind from you trying to solve my problem.
    I understand you needed some rest and hope you spent a good weekend.
    It was also weekend for us here!

    And I also know I'm not the only one on earth !!!
    Take your time...

    Thanks again,
    Best regards,

    Gerard

  13. #13
    Join Date
    Jan 2004
    Location
    India
    Posts
    168

    Thumbs up

    Please try this code. This should work. This is based on your request for single table.
    The table structure that you have give is ok. Based on that you can run this code.
    <?php
    function counting($username)
    {
    GLOBAL $db,$table;
    $username = trim($username);
    $sql = "SELECT * FROM $table WHERE userName = '$username'";
    $result = mysql_query($sql);
    $row = mysql_fetch_object($result);
    if($row)
    {
    $userhit = $row->userHit;
    $userhit=$userhit+1;
    $query = "UPDATE $table SET userHit='$userhit', logTime='time()' WHERE userName='$username'";
    mysql_query($query) or die(mysql_error());
    }
    else
    {
    echo "User Information Not Found";
    }
    return mysql_num_rows($query);
    }
    ?>

    Inform me if any more help needed.

    Regards
    Rajesh
    Last edited by rajesh_r_r; 06-29-04 at 23:43.

  14. #14
    Join Date
    Apr 2004
    Location
    Canada
    Posts
    57
    Thank you, Rajesh !
    It works great at first try, but... only for the hits, not for the time.
    Best regards,
    Gerard

  15. #15
    Join Date
    Jan 2004
    Location
    India
    Posts
    168

    Thumbs up

    Quote Originally Posted by Germaris
    Thank you, Rajesh !
    It works great at first try, but... only for the hits, not for the time.
    Best regards,
    Gerard
    Use this instead
    $query = "UPDATE $table SET userHit='$userhit', logTime='".time()."' WHERE userName='$username'";

    The time function is from php and it will retrun the timestamp. to display you have to use the date() function.
    The date() will work like this
    $strdate = date("F j, Y, g:i a", time()); // June 30, 2004, 12:16 pm

    The output depends on the timestamp you give. And the function will return a
    srting.
    Standard format
    string date ( string format [, int timestamp])

    Hope this will be fine.
    Feel free to ask any help.
    Regards
    Rajesh
    Last edited by rajesh_r_r; 06-30-04 at 05:05.

Posting Permissions

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