WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDESPHP CLASSESCODE SEARCHARTICLES SEARCHPHP FORUMSPHP MANUALPHP FUNCTIONS LISTWEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Join us on FaceBook
Submit a code Example / Snippet Submit Your Code
Poker Tournaments Poker Tournaments
Poker Guide for Developers Poker Guide for Developers
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Resources
Web Development Content
Internet Security Software
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
פרייסז - הכח לקנות עובר לידיים שלך
Texas Holdem Poker Evangelists

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : How to store the info about each shopper on your shopping cart? This is the code to track your "buyers" , you will want this info when getting an inquiry from them... Very neat, use session, include and select whether receive the data or not..
Categories : PHP, Ecommerce Update Picture
Maxim Maletsky
Date : Aug 17th 2000
Grade : 5 of 5 (graded 1 times)
Viewed : 5424
File : No file for this code example.
Images : No Images for this code example.
Search : More code by Maxim Maletsky
Action : Grade This Code Example
Tools : My Examples List

Submit your own code examples  Submit your own code examples 
 

If you have an e-commerce website with a shopping cart or just a database where lots of
people are searching and then when they are going to ask you for something (I mean via
webform) you, perhaps, might be very curiouse what is that they were looking at, where did
they spend more time, what item they might think "the sexiest" about...

Without asking them, (they might lie) you can simply track them..

Here I developed a peace of code that I use for my database:
It is not a "commercial" version, you definitelly will have to play with it, I did not modify it for
distribution, but It might be a good example or an ispiration for a similar idea:

It will work for sure on PHP4, with MySQL but can be avoid to use database, I also set it to
track everyone but receive that info only in case I'm being contacted by the visitor. I do not
this info anywhere unless it is sent to be by the visitor....

Here's the code:

FILE 1:
If you wish you can include() this in every file with include() function, but it is only useful when
there are many different files, on single-file software it would make no sense to include() it
from some other file..

Remember: set session ONLY before ANY output! otherwise it WILL NOT work.

<?
/*                Max() Tracker.
*         The piece of code to track visitor's adventures on your software.
*
*         Copyright (C) 2000 Maxim Maletsky, [maxim.maletsky@lincmedia.co.jp]
*         LINC Media Inc., J-Door.com, J@pan Inc.
*        
*         This software is FREEWARE.
*/

// The session is being registred here:
        session_register("PV");
        session_register("w3"); // here will arrive to us the time "from the past"

// Checking if this is first time to registed session and if it is then give the defauld (different)
value to the first record:
        if (IsSet($w3))
                $time_spent = (time() +1) - $w3; //making the time difference beetwen
the current one and the past, brought to us by cookie..
                        $w3 = time(); //remembers the present time...

$myReferer = ereg_replace($PV_SP, "@", $HTTP_REFERER); //Because I use column ":" as one
of my separators I want to get rid of it in URLs changing it with "@"

        if (!IsSet($PV) && $HTTP_REFERER) // there's no need to track every referer as long
as we know how did he get to this page at first place, later-on session will track him...
                $PV .="S".$PV_SP.$PV_SP.$myReferer.$PV_SP.$time_spent; // the default
first record
        if (!IsSet($PV) && !$HTTP_REFERER)
                $PV .="S".$PV_SP.$PV_SP."0".$PV_SP.$time_spent;

// below is not part of this file, this should not be on every page: see comments below :

        if ($profile) // in my case I need a little different record when the user sees profile of
an item, you will want to change it...
                $PV .="|".$area.$PV_SP.$id.$PV_SP.$myReferer.$PV_SP.$time_spent;
        else
                $PV .="|".$area.$PV_SP.$id.$PV_SP.$PV_SP.$time_spent; // and here's
the meat: add this on every reload of the page...

?>

FILE 2:
Here's how we will then process the aquired data and eventually what we will send to us in
case we need it.

Put this within the form:
<?
$PV .="|".$PV_SP.$PV_SP."P".$PV_SP.$time_spent;
?>

This is usually comes where the form is being processed:
Remember: the file above should be evrywhere, but not the $PV .= that is different as
menioned by me...

<?

$PV .="|".$PV_SP.$PV_SP."R".$PV_SP.$time_spent; // THE LAST IMPUT! !!! MAKE SURE THIS
IMPUT IS THE L;AST ONE !!!        
//echo $PV; // Uncomment it if you want to see what did you bring with you so far: (only for
testing purposes...)
$PV_array = split('[|]', $PV); // split the record in group of records belonging to each reload.
set it in an array.

// Here we will split it all on eby one, and review it, then set all that staff into what it should
be...
while (list($PVkey1, $PVval1)=each($PV_array)) {
        list ($v1, $v2, $v3, $v4) = split ($PV_SP, $PVval1); // the order here is vey
important, every variable is what is inside beetwen ":"

        $v3 = ereg_replace("@", $PV_SP, $v3); // Danger is over, let's get back
our "column"s instead of "@"s

        $all_time_spent =$all_time_spent + $v4; // calculates the total time

if ($v1 != "S") // incase this record is the "start" (the first one) the time is not needed to be
printed,
        $M_time =" time spent: </span><span class=\"com4\">".date ("H:i:s", mktime
(0,0,$v4))."</span><span class=\"link\"><br>"; //compose the time
elseif ($v3 == "P") // "P" is when you submit the form, it is there just to find out how long it
took the user fillin out the form, you will have to work on this ....
        $M_time =" </span><span class=\"com4\">".date ("H:i:s", mktime
(0,0,$v4))."</span><span class=\"link\"><br>";

/*
Now, here's one future that I cannot give to you because I didn't preparethis software to be
redistribuited, this is what I cut()ed and past()ed from my own script, I have a mysql class, so
here you see it, shange it to your own favorit mysql functions...
*/
        if ($v1 && $v2 && $v1 != "S")
        {
                        $pv1_mysql->query("SELECT a_field FROM a_table WHERE
id=$v1");
                        $pv1_mysql->fetch_record();
                        $PV_area = $pv1_mysql->Record;

                        $pv2_mysql->query("SELECT a_field FROM a_table WHERE
id=$v2");
                        $pv2_mysql->fetch_record();
                        $PV_id = $pv2_mysql->Record;

                $M_history ="<a href=\"http://www.j-door.com/experts.html?
area=".$v1."&id=".$v2."\">examined expert \"".substr ($PV_id['name'], 0, 15)."...\" in
\"".substr ($PV_area['name'], 0, 10)."...\" area</a>";
        }
        elseif ($v1 && !$v2 && $v1 != "S")
        {
                        $pv1_mysql->query("SELECT a_field FROM a_table WHERE
id=$v1");
                        $pv1_mysql->fetch_record();
                        $PV_area = $pv1_mysql->Record;

                $M_history ="<a href=\"http://www.j-door.com/experts.html?
area=".$v1."\">visited area \"".substr ($PV_area['name'], 0, 30)."...\"</a>";
        }
        elseif ($v1 != "S" && $v3 && $v3 != "R" && $v3 != "P")
        {
                        $pv2_mysql->query("SELECT a_field FROM a_table WHERE
id=$v2");
                        $pv2_mysql->fetch_record();
                        $PV_id = $pv2_mysql->Record;

                $M_history ="<a href=\"http://www.j-door.com/experts.html?
profile=".$v2."\">viewed profile of \"".substr ($PV_id['name'], 0, 30)."...\"</a> accessing it
from <a href=\"".$v3."\">\"".substr ($v3, 17)."\"</a>";
        }
        elseif ($v1 == "S" && !$v2 && $v3) // prints the last to lines with data about
submitting the form and the total time spent on the website:
        {
                if ($v3 == "0")
                        $M_history ="Came to Experts from Unknown Page";
                else
                        $M_history ="Came to Experts from <a
href=\"".$v3."\">".substr ($v3, 17)."</a>";
        }
        elseif ($v3 == "P")
                        $M_history ="submitted the form what took to him";
        elseif ($v3 == "R")
                        $M_history ="<p>Total time spent in Experts Area:";

        $myHistory .=$M_time.$M_history;
        }
//The hole shit above is now became one single variable ready to be added into message or
outputed with echo or whatever...
$myHistory =$myHistory." </span><span class=\"com4\">".date ("H:i:s", mktime
(0,0,$all_time_spent))."</span><span class=\"link\"><br>";        //The History variable
// that's it...
?>


I'm sure you can improve it, especially becaus ehow it is here right now it will not work at all,
you must find a way to use it, rewrite the code above, set some header, style shits, output,
tables, everything,.... but I hope it will clear up you idea on how to track people and how to
play with the info they bring with you...

I was asked: why do you make people bring with them an always increasing variable and not
simply make a class to add the data in mysql database while they are traveling,
well, I think it is better to bring it with you rather then to open childs in myqsl connect-
disconnect, insert... you might then not to need it, you might not to have mysql at all.

this is simplier, even if not too stable ....

Cheers!
Maxim Maletsky...

P.S: I will be glad to help you with your own version of this software..
GOT A         QUESTION? -- LET ME KNOW!



shopping cart class with add/edit/delete product functionality.
Categories : PHP, PHP Classes, Ecommerce
Example Shopping cart class
Categories : Ecommerce, PHP, PHP Classes
Amazon book cover handling
Categories : HTML and PHP, PHP, MySQL, Ecommerce
Credit Card Identification and Validation Class - The credit_card class provides methods for cleaning, validating and identifying the type of credit card numbers.
Categories : PHP, PHP Classes, Credit Cards, Ecommerce, Algorithms
simple shopping cart for php3
Categories : PHP, PHP Classes, Complete Programs, Ecommerce
Get TemplateMonster data
Categories : Arrays, Ecommerce, PHP, Strings
PHP-MySQL shopping cart
Categories : PHP, Ecommerce, Complete Programs
phpAds, a complete banner and ad management system with detailled tracking and stats.
Categories : MySQL, Complete Programs, Ecommerce, PHP, Databases
Validation function for LUHNMod10 and variant. Can discriminate credit card numbers of varying lengths. Uses [Double >> Sum-of-Digits] transform.
Categories : Credit Cards, Authentication, Ecommerce, PHP
PCAC (pretty cool auction client), auction client server applications
Categories : PHP, MySQL, Ecommerce
Amazon.com API, CURL-REST Parser. Obtain data about Amazon products (PHP5 +)
Categories : PHP, Ecommerce, XML, Web Services, CURL
Query2Report : Generating Html, Pdf and Csv Reports from SQL Query
Categories : PHP, PHP, HTML, PDF, Excel
How to validate an Israeli ID number.
Categories : Ecommerce, PHP, Algorithms
open source online php shop project ecommerce commerce
Categories : PHP, Ecommerce
ECHOcart - Open Source Shopping Cart
Categories : PHP, Credit Cards, Ecommerce
 Maxim Maletsky wrote :440
O yeah....  

$PV_SP is separator, so in my case it`s equale to ":"

basicly a record looks like this

|:::|:::|::: etc ... where $v1,2,3,4 are separated by column ":"

Cheers