Jump to content

User Session Information for 2 Pages


finkrattaz

Recommended Posts

I am trying to record when a user logs into a page and how long they were on the page. There two pages.

 

Page 1

 

<?php

session_start();

$_SESSION['view_start_sec_v1'] = date('s');

require_once('dbcon2.php');

if(isset($_POST['SUBMITME'])) {

$_SESSION['view_stop_sec_v1'] = date('s');

$dbr = new db;$dbr->dbuser();

$in = new customer;$in->inD($_POST['name'],$_POST['city'],$_POST['state'],$_POST['zip'],$_POST['make'],$_POST['model'],$_POST['completevideo'],$_POST['likevideo'],$_POST['purchasedvideo'],$_POST['comments'],1);

}

?>

 

Page 2

<?php

session_start();

$_SESSION['view_start_sec_v2'] = date('s');

require_once('dbcon2.php');

if(isset($_POST['SUBMITME'])) {

$_SESSION['view_stop_sec_v2'] = date('s');

$dbr = new db;$dbr->dbuser();

$in = new customer;$in->inD($_POST['name'],$_POST['city'],$_POST['state'],$_POST['zip'],$_POST['make'],$_POST['model'],$_POST['completevideo'],$_POST['likevideo'],$_POST['purchasedvideo'],$_POST['comments'],1);

}

?>

 

if ($_SESSION['view_start_sec_v1'] == $_SESSION['view_stop_sec_v1'])

{

// Its still the same hour..so parsing is fine.

$total_time_v1 = $_SESSION['view_stop_sec_v1'] - $_SESSION['view_start_sec_v1'];

$total_time_v2 = $_SESSION['view_stop_sec_v2'] - $_SESSION['view_start_sec_v2'];

$vp1_query = sprintf("INSERT INTO session(name, url_viewed, date_viewed,time_viewed) VALUES('%s','%s','%s','%s')", $name, 'VideoPage1',date('m/d/Y'), $total_time_v1);

$vp2_query = sprintf("INSERT INTO session(name, url_viewed, date_viewed,time_viewed) VALUES('%s','%s','%s','%s')", $name, 'VideoPage2',date('m/d/Y'), $total_time_v2);

mysql_query($vp1_query);

mysql_query($vp2_query);

}

 

Also in the database the time_viewed is set to VARCHAR and I don't know if it correct.

 

http://stealthtrackervideos.com is the site and the page where viewing the database is http://stealthtrackervideos.com/Session.php - Time Viewed is coming up as zero.

Link to comment
https://forums.phpfreaks.com/topic/101356-user-session-information-for-2-pages/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.