|
|
|
| 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 |
 Maxim Maletsky |
| Date : |
Aug 17th 2000 |
| Grade : |
5 of 5 (graded 1 times) |
| Viewed : |
4139 |
| 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 |
|
|
|
|
|
|
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!
|
|
| phpAds, a complete banner and ad management system with detailled tracking and stats. Categories : MySQL, Complete Programs, Ecommerce, PHP, Databases | | | open source online php shop project ecommerce commerce Categories : PHP, Ecommerce | | | an example of the cyberlib payment class Categories : PHP, PHP Classes, Ecommerce, Credit Cards | | | PHPCatalog Categories : Ecommerce, PHP, Complete Programs | | | Amazon book cover handling Categories : HTML and PHP, PHP, MySQL, Ecommerce | | | shopping cart class with add/edit/delete product functionality. Categories : PHP, PHP Classes, Ecommerce | | | ECHO-PHP Class Real Time Transaction Processor v1.4.4 for Credit Cards and
Checks / ACH Categories : PHP Classes, Cybercash, Classes and Objects, Ecommerce, PHP | | | Shopping Basket On-Line Ordering System. Categories : Complete Programs, MySQL, PHP, Ecommerce, Databases | | | ECHOcart - Open Source Shopping Cart Categories : PHP, Credit Cards, Ecommerce | | | This is a redirection program which is as good as the come.to v3 url
redirection, complete with admin interface all clients stored in mysql
Categories : PHP, MySQL, Ecommerce, HTML and PHP, Complete Programs | | | Amazon.com API, CURL-REST Parser. Obtain data about Amazon products (PHP5 +) Categories : PHP, Ecommerce, XML, Web Services, CURL | | | 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 | | | Barcodes On The Fly With GD Categories : Ecommerce, Graphics, HTML and PHP, PHP | | | Credit Card validation routine. Uses MOD 10 to check if credit card number is valid. Categories : Ecommerce, Credit Cards, PHP, Complete Programs | | | REALTIME SHIPPING QUOTE Categories : Complete Programs, Ecommerce, PHP | |
| | | | 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
| |
|
|
|