2013-07-03 39 views
-1

我们正在编写一个简单的视频播放器,它的部分功能是发送一个简单的GET请求到Web服务器上的PHP页面,以便用客户的活动(即,他们正在观看的视频的ID,他们是什么样的地位,他们的用户ID):当页面没有从浏览器请求页面时,PHP的行为不同

listener.php?user=1&time=59000&movie_id=35003 

这listener.php很简单,它会检查是否已经存在一排这个特殊用户ID和电影ID:

SELECT orders_products_id, 
    products_date_last_watched as lasttime, 
    now() as now, 
    products_timewatched 
    from orders_products 
    where products_id = '" . $product_id . "' and 
    customers_id = '" . $customer_id ."' 

其次是:

if ($check['orders_products_id'] > 0) 

如果属实,这将运行一个UPDATE语句

如有虚假,它会运行一个INSERT语句

现在的问题是,如果我在我的浏览器,并改变加载这个listener.php值直接在URL中,它按预期工作。

但是,当程序调用同一页面时,它总是以插入新行的方式结束。服务器的日志显示正确的URL:

"GET /listener.php?user=1&time=128142&movie_id=35003 HTTP/1.1" 200 - "-" "Mozilla/5.0" 

任何想法?这是在Windows 2008R2上的XAMPP测试服务器上运行的,如果这有什么区别?

编辑:这里是全码:

header("Cache-Control: no-cache, must-revalidate"); 
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); 

include('includes/application_top.php'); 


$user_id = $_GET['user']; 
$lastpos = $_GET['time']; 
$product_id = $_GET['movie_id']; 
$episode = 0; 

//check for existing listing 
$check_query = tep_db_query("SELECT orders_products_id, products_date_last_watched as lasttime, now() as now, products_timewatched from orders_products where products_id = '" . $product_id . "' and customers_id = '" . $customer_id ."' and products_lastepisode = '" . $episode . "'"); 
$check = tep_db_fetch_array($check_query); 

if ($check['orders_products_id'] > 0) { 
//user has already watched this 


//find seconds between last timestamp and now 
$starttime = strtotime($check['lasttime']); 
$endtime = strtotime($check['now']); 
$difference = $endtime - $starttime; 

if ($difference < 60) { 
    $totaltime = $check['products_timewatched'] + $difference; 
} else { 
    $totaltime = $check['products_timewatched']; 
} 

$update_query = "UPDATE orders_products set products_lastposition = '" . $lastpos ."', products_date_last_watched = now(), products_lastepisode = '" . $episode . "', products_timewatched = '" . $totaltime . "', products_platform = '" . $_SERVER['HTTP_USER_AGENT'] . "', customers_ip = '" . $_SERVER['REMOTE_ADDR'] ."' where orders_products_id = '" . $check['orders_products_id'] ."'"; 
tep_db_query($update_query); 

} else { 

//create new entry 
if ($user_id != 999999999){ 
    tep_db_query("INSERT INTO orders_products (products_date_first_watched, products_visible, products_date_last_watched, customers_id, products_id, products_lastposition, products_lastepisode, products_timewatched) values (now(), 1, now(), '" . $user_id . "', '" . $product_id . "', '" . $lastpos ."', '" . $episode . "', 0)"); 
} 
} 

一些注意事项: - “tep_db_query”为MySQL查询,因为我使用的自从职能的改进版本,它的功能也可以通过标准的mysql_query和mysql_fetch_array - 用户ID 99999999意味着它是一个guest用户和他们的活动不应该被记录 - 整个“//找到最后的时间戳和现在之间秒”是跟踪的总时间花费

+1

你能发布完整的脚本吗? – j08691

+0

将查询作为调试回显到错误日志中。我敢打赌你没有得到正确的参数? – Nanne

+0

由于他正在使用MySQL函数中的NOW()而不是他所拥有的日期字段,所以时间总是不一样。 – Prix

回答

0

没关系,我我是一个白痴...... URL变量是$ user_id,但我在SQL查询中查找了$ customer_id ... facepalm

相关问题