2013-07-03 3 views
-1

간단한 비디오 플레이어를 작성하고 있으며 일부 기능은 웹 서버의 PHP 페이지에 간단한 GET 요청을 보내 고객의 데이터베이스로 데이터베이스를 업데이트하는 것입니다. 활동 (즉, 그들이 무엇 위치가보고있는 비디오의 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) 

true의 경우,이 UPDATE 문

경우는 false를 실행합니다, 지금 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)"); 
} 
} 

일부 노트 : 여기에 전체 코드 - MySQL의 쿼리 "tep_db_query는"표준는 mysql_query와 같은 기능적으로 나는 osCommerce에의 기능의 수정 된 버전을 사용하고 있기 때문에, 그것의와 로 MYSQL_ASSOC - 사용자 ID 99999999 그것은 게스트 사용자이며, 그들의 활동이 기록해서는 안 의미 - "이제 마지막 타임 스탬프와 사이의 시간 (초)을 발견 //"전체를 내가 신경 쓸

+1

전체 스크립트를 게시 할 수 있습니까? – j08691

+0

쿼리를 디버그로 오류 로그에 에코합니다. 올바른 매개 변수를 얻지 못했을까요? – Nanne

+0

잘 시간은 그가 MySQL 함수에서'NOW()'를 사용하고 있기 때문에 항상 다르며 그가 가지고있는 날짜 필드가 아닙니다. – Prix

답변

0

을 보내는 총 시간을 추적하는 것입니다 바보 같다 ... URL 변수 $ user_id이지만 SQL 쿼리에서 $ customer_id를 조회했습니다 ... facepalm

관련 문제