|
|
 |
| Beginning PHP Beginning-level PHP discussions. More advanced coders should post to the Pro PHP forum. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Beginning PHP section of the Wrox p2p Programmer to Programmer discussion community. This is a community of more than 40,000 computer programmers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining our free Wrox p2p community you can post your own programming questions and respond to other programmers’ questions. Registered users also don't have to see the ads that are displayed to guests. Registration is fast, simple and absolutely free so please, join today!
Join today and post to win prizes! Post more to increase your chances of being Wrox’s top poster of the month.
|
 |

October 2nd, 2009, 11:58 AM
|
|
Registered User
|
|
Join Date: Sep 2009
Posts: 6
Thanks: 1
Thanked 1 Time in 1 Post
|
|
problem regarding cookies.
Another questoin after two answered questions. Okkk! This is the problem regarding cookies. where i am creating a mysql table and storing the information of each visit by the browsers. if browser has visited the site. it will treat that as old user. else it will insert the information of new user in database. But the problem is: " Every time it is creating a new row in table and treating each attempt as a new attempt." Can any one help me about this? I am sending the format of the database also. Try it............
create table track_visit (
id INT NOT NULL AUTO_INCREMENT,
PRIMARY KEY( id ),
first_visit INT,
last_visit INT,
num_visits INT,
total_duration INT,
total_clicks INT
);
************************************************** ************************************************** ****************
<?php
$link = mysql_connect( "localhost", "root", "root" );
if ( ! $link )
die( "Couldn't connect to mysqld" );
mysql_select_db( "test", $link ) or die ( mysql_error() );
if ( ! isset ( $visit_id ) ) {
$user_stats = newuser( $link );
}
else {
$user_stats = olduser( $link, $visit_id, $slength );
print "Welcome back $visit_id<P>";
}
function newuser( $link )
{
// a new user!
$visit_data = array (
first_visit => time(),
last_visit => time(),
num_visits => 1,
total_duration => 0,
total_clicks => 1
);
// $visit_data[id] = mysql_insert_id();
// setcookie( "visit_id", $visit_data[id], time()+(60*60));
$query = "INSERT INTO track_visit ( first_visit,
last_visit,
num_visit,
total_duration,
total_clicks ) ";
$query .= "values( $visit_data[first_visit],
$visit_data[last_visit],
$visit_data[num_visits],
$visit_data[total_duration],
$visit_data[total_clicks] )";
$result = mysql_query( $query );
$visit_data[id] = mysql_insert_id();
setcookie( "visit_id", $visit_data[id], time()+(60*60),"/");
echo "<script type=text/javascript>window.alert(\"Finish of the line.\")</script>";
return $visit_data;
}
function olduser( $link, $visit_id, $slength )
{
// s/he's been here before!
$query = "SELECT * FROM track_visit WHERE id=$visit_id";
$result = mysql_query( $query );
if ( ! mysql_num_rows( $result ) )
// cookie found but no id in database -- treat as new user
return newuser( $link );
$visit_data = mysql_fetch_array( $result, $link );
// there has been another hit so increment
$visit_data[total_clicks]++;
if ( ( $visit_data[last_visit] + $slength ) > time() )
// still in session so add to total elapsed time
$visit_data[total_duration] +=
( time() − $visit_data[last_visit] );
else
// this is a new visit
$visit_data[num_visits]++;
// update the database
$query = "UPDATE track_visit SET last_visit=".time().",
num_visits=$visit_data[num_visits], ";
$query .= "total_duration=$visit_data[total_duration],
total_clicks=$visit_data[total_clicks] ";
$query .= "WHERE id=$visit_id";
$result = mysql_query( $query );
return $visit_data;
}
?>
************************************************** ************************************************** ****************
Another problem. Can i shift my default cookies address in windows? If it is possible then what is method or steps to change the default cookies address?
Keep in mind, i am saying about windows invironment.
Waiting for reply.......
Another roblem is not able to set the duration time in table.
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
 |