p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


Go Back   p2p.wrox.com Forums > PHP/MySQL > Beginning PHP
I forgot my password Register Now
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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.

Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old October 2nd, 2009, 11:45 AM
Registered User
Points: 58, Level: 1
Points: 58, Level: 1 Points: 58, Level: 1 Points: 58, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Sep 2009
Posts: 6
Thanks: 1
Thanked 1 Time in 1 Post
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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
problem with getting cookies kanoorani JSP Basics 1 June 18th, 2007 01:51 AM
cookies problem kanoorani Servlets 0 December 22nd, 2006 10:54 AM
Problem with using cookies JSB Beginning PHP 0 November 25th, 2005 11:58 AM
Problem with cookies :( Varg_88 Classic ASP Databases 2 December 13th, 2004 11:34 AM
.NET cookies - privacy set to: block all cookies daryl ASP.NET 1.1 1 April 6th, 2004 03:08 PM



All times are GMT -4. The time now is 06:30 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
© 2008 Wiley Publishing, Inc