Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

[8ef111]: dlcounter.php Maximize Restore History

Download this file

dlcounter.php    105 lines (100 with data), 3.7 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
<?php
/*
** Hugin Download Counter
** (C) 2007-2010 Yuval Levy
** Permission is hereby granted, free of charge, to any person obtaining
** a copy of this software and associated documentation files (the
** "Software"), to deal in the Software without restriction, including
** without limitation the rights to use, copy, modify, merge, publish,
** distribute, sublicense, and/or sell copies of the Software, and to
** permit persons to whom the Software is furnished to do so, subject to
** the following conditions:
**
** The above copyright notice and this permission notice shall be
** included in all copies or substantial portions of the Software.
**
** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
** NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
** LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
** OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
** WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
// magic quotes off - we'll explicitly escape strings
set_magic_quotes_runtime(0);
// database
$mysql_host='localhost';
$mysql_user='ENTER_USER_HERE';
$mysql_pw='ENTER_PW_HERE';
$mysql_db='ENTER_DB_HERE';
/*******************************************************************************
table for counter
CREATE TABLE hd_hugin_dl (
# unique revision identifier
hd_rev CHAR(12) NOT NULL UNIQUE,
# counter
hd_count INT(11) UNSIGNED NOT NULL DEFAULT 0,
# timestamp of the last update
hd_ts TIMESTAMP(14),
# keys
PRIMARY KEY v(hd_svn)
);
*******************************************************************************/
/*******************************************************************************
** sanitize input **
*******************************************************************************/
// http://ca3.php.net/manual/en/ref.filter.php
// http://devzone.zend.com/node/view/id/1113
$defs = array (
'svn' => array (
'filter' => FILTER_VALIDATE_INT,
'options' => array ('min_range' => 1,
'max_range' => 6000
),
),
'hg' => array (
'filter' => FILTER_VALIDATE_INT,
'flags' => array(FILTER_FLAG_ALLOW_HEX)
)
);
$input=filter_input_array(INPUT_GET,$defs);
$svn=$input['svn'];
$hg=$input['hg'];
/*******************************************************************************
** register hit **
*******************************************************************************/
if($hg){$svn=$hg;}
if($svn){
// http://www.phpfever.com/mysqli-tutorial.html
// connect to DB
$mysqli = new mysqli($mysql_host, $mysql_user, $mysql_pw, $mysql_db);
// check connection
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
$query = 'SELECT hd_count FROM hd_hugin_dl WHERE hd_svn='.$svn;
if($result = $mysqli->query($query)){
$row=$result->fetch_assoc();
$count=$row['hd_count']+1;
$query2 = 'REPLACE INTO hd_hugin_dl SET
hd_count='.$count.',
hd_rev="'.$svn.'"';
if(!$mysqli->query($query2)){
$msg='<h1>'.sprintf("Error - SQLSTATE %s.\n", $mysqli->sqlstate).'</h1>';
}
}
// close connection
$mysqli->close();
}
if($hg){
// TODO: how do we know that a specific hg revision is current or outdated?
} else {
if($svn<4262){
header('Location: http://hugin.sf.net/installed/oldv.shtml');
}else{
header('Location: http://hugin.sf.net/installed/');
}
}
?>