Page 3 of 3 FirstFirst 123
Results 21 to 25 of 25

Thread: Need scripts that lists how many times file downloaded

  1. #21
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,377
    Thanks
    77
    Thanked 3,421 Times in 3,382 Posts
    Blog Entries
    12

    Default

    You could use an iframe or AJAX. Using iframe is easiest. Make up a php file called display_counter.php and put the php code on it:

    Code:
    <?php echo file_get_contents('path/to/counter.txt');?>
    Then on your HTML page have an iframe:

    Code:
    <iframe name="counter" src="display_counter.php" width="90" height="30" scrolling="no" frameborder="0"></iframe>
    You could even skip the step of the intermediate php page and just do:

    Code:
    <iframe name="counter" src="path/to/counter.txt" width="90" height="30" scrolling="no" frameborder="0"></iframe>
    But sometimes displaying a text file in an iframe can fail. If you rename it to counter.htm (make sure to also change wherever it's referenced in the other code, so it gets updated), then there should be no problem.

    Using AJAX for this is complicated, and really a bit of overkill for such a simple piece of information unless you already have jQuery on the page, in which case it's fairly simple to load the contents of the counter file into a div element on the page. Again, it would be best if it were a .php or .htm file, but probably less critical than with iframe.
    Last edited by jscheuer1; 03-19-2017 at 11:21 AM. Reason: syntax
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  2. #22
    Join Date
    Jul 2008
    Location
    Derbyshire, UK
    Posts
    3,035
    Thanks
    25
    Thanked 599 Times in 575 Posts
    Blog Entries
    40

    Default

    Quote Originally Posted by Kusu View Post
    Here,

    Thank You, Beverleyh.

    Step 1,2,3 worked for me but Step no.4 didn't gave me result.
    Because i was having my page where result was to shown was html page not php page.
    So I want the code of Step 4 in html format!

    Can this be done? If possible how?

    Waiting for reply, Thank You again...
    Depending on what your web host allows, you might be able to use .htaccess to parse PHP in HTML pages. Try these http://deano.me/2015/12/php-inside-h...sing-htaccess/

    Hope that helps
    Focus on Function Web Design
    Fast Edit (A flat file, PHP web page editor & CMS. Small, FREE, no database!) | Fast Edit BE (Snippet Manager) (Web content editor for multiple editable regions!) | Fast Apps

  3. #23
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,377
    Thanks
    77
    Thanked 3,421 Times in 3,382 Posts
    Blog Entries
    12

    Default

    Isn't it generally a bad idea to parse all HTML as PHP? Here's another bad idea (though it can be fine if you don't use the highlighted update feature too much):

    Code:
    <!DOCTYPE html>
    <html>
    <head>
    <title>Simple AJAX Demo</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <style type="text/css">
    #downloadcount {font: normal 95% verdana, arial, sans-serif;}
    </style>
    </head>
    <body>
    <div id="downloadcount">Number Downloaded: <span id="result"></span></div>
    <script>
    (function(url){
    	var xhttp = new XMLHttpRequest();
    	xhttp.onreadystatechange = function() {
    		if (this.readyState === 4 && this.status === 200) {
    			document.getElementById('result').innerHTML = this.responseText;
    		}
    	};
    	xhttp.open('get', url + '?bust=' + new Date().getTime(), true);
    	xhttp.send();
    	setInterval(function(){
    		xhttp.open('get', url + '?bust=' + new Date().getTime(), true);
    		xhttp.send();
    	}, 3 * 60 * 1000);
    })('counter.txt'); // use full path to counter.txt
    </script>
    </body>
    </html>
    If you don't need it updated, remove the highlighted. Currently it's set to update every 3 minutes, which is reasonable in most cases.
    Last edited by jscheuer1; 03-19-2017 at 01:25 PM. Reason: minor code improvement
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  4. #24
    Join Date
    Jul 2008
    Location
    Derbyshire, UK
    Posts
    3,035
    Thanks
    25
    Thanked 599 Times in 575 Posts
    Blog Entries
    40

    Default

    I wouldn't say it's generally a bad idea to parse PHP in HTML. It makes the server work a little harder, yes, and it may create a bit of confusion with the organisation of files if somebody is expecting to see HTML in an .html file and PHP in a .php file (although with internal CSS and JavaScript already in HTML, and HTML in PHP, what's a little PHP in HTML going to do to the confusion level?), so I suppose the answer would be "it depends". To be honest, most of the web hosts and server environments I've worked on in the last 10 years had been setup to parse PHP in HTML files by default and I haven't had to fiddle with .htaccess at all. Maybe that's because they're private servers, semi-dedicated servers and "pro" level accounts on shared hosting though? It could be that more basic level shared hosting doesn't allow it.
    Focus on Function Web Design
    Fast Edit (A flat file, PHP web page editor & CMS. Small, FREE, no database!) | Fast Edit BE (Snippet Manager) (Web content editor for multiple editable regions!) | Fast Apps

  5. #25
    Join Date
    Mar 2017
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Thank you for reply.

    Dear Beverleyh,

    I tried with step 4. i tried edit the value 0 to 55 or random number, it was working fine n showed the result.

    But when i click the link it redirect to file link and opens it but doesn't increase the count by 1.

    Counting is not done, i should say.

    What to do?

Similar Threads

  1. torrent file scripts
    By willy108 in forum PHP
    Replies: 4
    Last Post: 09-25-2007, 08:03 AM
  2. many scripts in one file
    By marringi in forum Other
    Replies: 0
    Last Post: 06-20-2007, 04:42 PM
  3. 2 Scripts on same html file.
    By Antonisid in forum Dynamic Drive scripts help
    Replies: 5
    Last Post: 04-26-2007, 07:30 PM
  4. Replies: 1
    Last Post: 08-20-2005, 10:44 AM
  5. How can I prevent a file from being downloaded?
    By inyiss in forum Dynamic Drive scripts help
    Replies: 2
    Last Post: 03-08-2005, 03:13 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •