| Export Citation |
Viewed in 1307 times. Downloaded in 500 times.
| © 2008 World Agroforestry Centre. All Rights Reserved. Copyright & Disclaimer |
|
function download_pub_file() { $url = check_url($_GET['file']); $pub_id = $_GET['pub_id']; $first_last = $_GET['first_last']; $cookie_name = "pub_".$pub_id; /** * Step-3: check if the url is valid or not */ if (is_valid_file_url(htmlspecialchars($url)) && $first_last=='ok' && !isset($_COOKIE[$cookie_name])) { /** * Step-4: update counter data (only if the URL is valid and file exists) */ update_num_of_download($pub_id); setcookie($cookie_name, "downloaded", time()+9000); } /** * Step-5: redirect to the original URL of the file */ header('Location: ' . $url); exit; } function update_num_of_download($pub_id) { $sql_query = sprintf("INSERT INTO tbldownloadcount VALUES (%d,1) ON DUPLICATE KEY UPDATE download_times=download_times+1;", $pub_id); db_pub_query($sql_query); } function is_valid_file_url($url) { // replace space characters in the URL with '%20' to support file name // with space characters $url = preg_replace('/\s/', '%20', $url); if (!valid_url($url, true)) { return false; } if (!url_exists($url)) { return false; } return true; // it seems that the file URL is valid } function url_exists($url) { if (@fopen($url,"r")) { return true; } else { return false; } } ?>
| Export Citation |
Viewed in 1307 times. Downloaded in 500 times.
| © 2008 World Agroforestry Centre. All Rights Reserved. Copyright & Disclaimer |
|