fullyloaded Posted October 26, 2006 Share Posted October 26, 2006 hiim looking for away to count how many times a program was downloaded from my site any idea how thanks Quote Link to comment https://forums.phpfreaks.com/topic/25137-download-count/ Share on other sites More sharing options...
.josh Posted October 26, 2006 Share Posted October 26, 2006 you would make a link to a page and the link would have an id pass to it. You would then update a field in your database based on the id and then output the filename based on the id. Quote Link to comment https://forums.phpfreaks.com/topic/25137-download-count/#findComment-114611 Share on other sites More sharing options...
redarrow Posted October 26, 2006 Share Posted October 26, 2006 The id is comming from a session in my example good luck.url.php [code]<?php session_start();echo "<a href='update_counter.php?id=$id&cmd=update'>goto the page you want</a>";?>[/code]update_counter.php[code]<?php session_start();if($_GET['cmd']=='update'){$query="UPDATE counter set stats=stats+1 WHERE id='$id'";result=mysql_query($query);header("location: To the page where the user wanted to go from the link.php");}else{header("location: back to home page if they go to this update page directly");}?>[/code]if you use the above defult then your be adding a count of 1 to the stats table but if you added 100 to the stats table and used A - YOUR BE DEDUCTING FROM 100 OK. Quote Link to comment https://forums.phpfreaks.com/topic/25137-download-count/#findComment-114665 Share on other sites More sharing options...
.josh Posted October 26, 2006 Share Posted October 26, 2006 okay first of all:[quote]if you use the above defult then your be adding a count of 1 to the stats table but if you added 100 to the stats table and used A - YOUR BE DEDUCTING FROM 100 OK.[/quote]that makes absolutely no sense at all. I [i]think[/i] you are giving an example of an alternate way to keep track, like counting up vs. counting down? 2nd, Can you please explain to me how your code has anything to do with sessions? I mean, I can sorta kinda see that you are providing an example of listing the id's for the links, but I fail to see how that's even remotely necessary? I would assume that one would do a query of some kind to get the id numbers, creating the links in a loop, or some other such similar fashion. I don't really see the point in carrying over the list of IDs in a session. I hope that you are not trying to say that $_GET variables are session variables.. Quote Link to comment https://forums.phpfreaks.com/topic/25137-download-count/#findComment-114805 Share on other sites More sharing options...
redarrow Posted October 27, 2006 Share Posted October 27, 2006 Crayon Violent sorry if my code made no scence but hopefully this does all the best redarrow. This code will dispaly 3 links and if the link is pressed will goto a update page and then the user is tacken to the page they wanted.if the user goes directly to the update page the page takes them to your home page (index.php)All you got to do is copy and past the code and add the database information.warning. I have used the ob_start and ob_flush_end on the code to stop header problams but if you get header erros then you should relly sort them out all the best redarrow.The last thing i want to exsplain your see in the query that i got the stats=stats+1 that adds a 1 each time the link is pressed and for the correct page example index.php.But if you insert in stats a number of 100 you can then count downwords examlpe stats=stats-1 this would take one from the 100 and ecah time deduct 1 from the database.hope you understand cheers.databse information.[code]create database page_stats;use page_stats;create table counter(id int not null primary key auto_increment,page_name varchar(20) not null ,stats int not null);insert into page_stats (page_name,stats) values (index.php,'1');insert into page_stats (page_name,stats) values (contact.php,'1');insert into page_stats (page_name,stats) values (links.php,'1');[/code]test.php[code]<?php // set an array for the links to display and the pages needed.$page=array(index_page =>'index.php',contact_page =>'contact.php',links_page =>'links.php');// for loop the amount of pages there are. for($i=1; $i<2; $i++){// get the information from the array.foreach($page as $v => $x){// echo the three links.echo "<a href='test_result.php?cmd=update&page_name=$x'>$v</a><br>";} }?>[/code]test_result.php[code]<?php// so the header does not error out a message.ob_start();// post the varables.$page_name=addslashes($_POST['page_name']);$stats=addslashes($_POST['stats']);// database connection.$db=mysql_connect('localhost','xxxxxx','xxxxxxxx');mysql_select_db('page_stats',$db);// $_GET the url condirition.if($_GET['cmd']=='update'){//get the current url to convert.$page=$_SERVER['REQUEST_URI'];//convert the url to use the end condition from the url. $page_name=ereg_replace("^\/+[A_Za-z]+.(php)\?(cmd)\=(update)\&(page_name)\=",' ',$page);// query the database to insert the stats to the correct .php page.$query="UPDATE counter set page_name='$page_name',stats=stats+1 where page_name='$page_name' and stats='$stats'";// query result.$result=mysql_query($query) or die("query problam error");// go to a page that the user wanted from the link.header("location: $page_name");//else}else{// goto the index page if the use goes ot this page directly.header("location: index.php"); }// end the flush for stopping a error header mesage.ob_end_flush();?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/25137-download-count/#findComment-115237 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.