PDA

View Full Version : Create Own Download Script



Conqueror
June 11th, 2002, 09:17
Ok, i know how to create tables and insert data
but i have some problems.
i am hosting download website.

I need to count how many hits for each link.
Can anyone teach me how to do that? I only need to log the hits.

Here's the situation. i would like to fetch the hits from mySQL table, increase it, then store it back to the mySQL table by using PHP.

Simple ones will be enough. Thanks.

I am learning PHP and mySQL. so i hope some of the experts could help me out

hohoho
June 11th, 2002, 11:14
mysql_query("UPDATE counter SET dls = dls + 1");

nag
June 11th, 2002, 11:39
Here is the complete script according to your need


<?

include ("vars.php");

$mysqlconnect = mysql_connect($dbhost, $dbuser, $dbpass);
mysql_select_db($db, $mysqlconnect);

if ($url==""){exit;}

if ($show)
{
$query = "SELECT downloads FROM $dbcountertable WHERE url = '$url'";
$result = mysql_db_query($db, $query, $mysqlconnect) or die ("Error in query: $query. " . mysql_error());
list($downloads) = mysql_fetch_row($result);
if ($downloads=="")
{
echo ("0");
}
else
{
echo ("$downloads");
}
}
else
{
$query = mysql_query("SELECT * from $dbcountertable WHERE url='$url'");
$result = mysql_fetch_array($query);
if ($result)
{
$query = "SELECT downloads FROM $dbcountertable WHERE url = '$url'";
$result = mysql_db_query($db, $query, $mysqlconnect) or die ("Error in query: $query. " . mysql_error());
list($downloads) = mysql_fetch_row($result);
$downloads = $downloads + 1;
$query = "UPDATE $dbcountertable SET downloads = '$downloads' WHERE url = '$url'";
$result = mysql_db_query($db, $query, $mysqlconnect) or die ("Error in query: $query. " . mysql_error());
}
else
{
$query = "INSERT INTO $dbcountertable (url,downloads)
VALUES ('$url','1')";
mysql_query($query) or die ("Error in query: $query. " . mysql_error());
}
echo ("<meta http-equiv=refresh content=0;url=$url>");
}
?>

Johnny
June 11th, 2002, 12:33
if you want.. i download a free php script that logs every hit, unque, raw, ratio, what page the person click that think (i think they ahve that not sure. , etc.. it seems easy to set up.. i don't knwo where i got it but fi you need it.. email me i send it to you.

Conqueror
June 11th, 2002, 21:17
Thanks nag for your complete details. i guess i know some of it what it means ;)
Thanks a lot

and Thanks to Johnny too, thanks for your offer. but i don't need it cause i am learning PHP. i need to look at the source code and modify it :)

Conqueror
June 11th, 2002, 21:24
Hi nag
what is this means?

echo ("<meta http-equiv=refresh content=0;url=$url>");

the page will refresh, according to the $url :confused:

nag
June 12th, 2002, 02:43
yes the same thing ,i think you do not know html headers in detail


echo ("<meta http-equiv=refresh content=0;url=$url>");

This is a HTML header statement it is used as

<meta http-equiv=refresh content=0;newurl>

Note that here "0" is the time in seconds after which page would refresh so if you want to refresh your page after 5 seconds and then want it to redirect to new url then HTML statement would

<meta http-equiv=refresh content=5;http://yahoo.com>
:)

Conqueror
June 12th, 2002, 08:52
Hi, i would like to know how to insert the file location into mySQL database?

i.e : mydomain.com/download/internet.zip

how can i add the URL into mySQL Tables?

nag
June 14th, 2002, 09:53
yes the same way, you can add URL's into mySQL tables as simple text by INSERT INTO....

Conqueror
June 15th, 2002, 00:30
Thanks nag :)
Thanks a lot..

nag
June 15th, 2002, 04:54
Always welcome:p

jetalomar
June 15th, 2002, 14:06
print $PHP_SELF; that will print the current url

dot5hosting
June 17th, 2002, 08:10
nag, should i put auto_increment in the downloads when i create tables for it ?

nag
June 17th, 2002, 09:00
list($downloads) = mysql_fetch_row($result);
$downloads = $downloads + 1;
$query = "UPDATE $dbcountertable SET downloads= '$downloads' WHERE url = '$url'";


No As you can see we have no need for it as we are incrementing it by ourselves,we do not want it to automatically increment whenever we put a record in it!