How could i impiment a system like this?

Discussion in 'PHP' started by Robert Allen, Nov 3, 2006.

  1. #1
    Hi,

    I want to create an incentive system for posters, so that when they get xx posts they can download xx file. How could i create such a system using vBulletin 3.6.0.

    Thanks for any suggestions,

    Rob
     
    Robert Allen, Nov 3, 2006 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    
    <?php
    
    define('MAX_POSTS', 100);
    
    define('THIS_SCRIPT', 1);
    define('LOCATION_BYPASS', 1);
    
    include('./global.php');
    
    if ($vbulletin->userinfo['posts'] >= MAX_POSTS)
    {
    	// Download file
    }
    else
    {
    	echo 'Sorry, you need '. MAX_POSTS .' posts to be able to download this file.';
    }
    
    ?>
    
    Code (markup):
     
    nico_swd, Nov 3, 2006 IP
    Robert Allen likes this.
  3. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #3
    You're welcome, lol....
     
    nico_swd, Nov 6, 2006 IP
  4. Robert Allen

    Robert Allen Peon

    Messages:
    2,685
    Likes Received:
    247
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Sorry i forgot the thread. Thanks for the fast reply and code.

    {
    	// Download file
    }
    Code (markup):
    Do i add my download URL in that line?

    Rep added.

    Rob
     
    Robert Allen, Nov 12, 2006 IP
  5. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #5
    What do you want to do? Display a download link, or let PHP send the file directly to the browser?
     
    nico_swd, Nov 12, 2006 IP
  6. Robert Allen

    Robert Allen Peon

    Messages:
    2,685
    Likes Received:
    247
    Best Answers:
    0
    Trophy Points:
    0
    #6
    I would rather not have the source of the download revieled,so i think the php should send the file.

    Thanks again for the help,

    Rob
     
    Robert Allen, Nov 14, 2006 IP
  7. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #7
    Untested, but give it a try.
    
    <?php
    
    $filepath = '/path/to/file/file.exe';
    define('MIN_POSTS', 100);
    
    
    define('THIS_SCRIPT', 1);
    define('LOCATION_BYPASS', 1);
    
    include('./global.php');
    
    if ($vbulletin->userinfo['posts'] >= MIN_POSTS)
    {
    	exit('Sorry, you need at least '. MIN_POSTS .' to download this file.');
    }
    
    if (!file_exists($filepath))
    {
    	exit('The file could not be found.');
    }
    
    ob_end_clean();
    
    header('Cache-Control: no-store, no-cache, must-revalidate');
    header('Cache-Control: post-check=0, pre-check=0', false);
    header('Pragma: no-cache');
    header('Expires: '. gmdate('D, d M Y H:i:s', mktime(date('H')+2, date('i'), date('s'), date('m'), date('d'), date('Y'))).' GMT');
    header('Last-Modified: '. gmdate('D, d M Y H:i:s').' GMT');
    header('Content-Type: application/octet-stream');
    header('Content-Length: '. filesize($filepath));
    header('Content-Disposition: attachment; filename="'. basename($filepath) .'"');
    header('Content-Transfer-Encoding: binary');
    
    
    if (!($file = @fopen($filepath, 'rb')))
    {
    	exit();
    }
    
    while (!feof($file) AND connection_status() == 0)
    {
    	echo fread($file, 1024 * 8);
    }
    
    flush();
    
    exit();
    
    ?>
    
    PHP:
     
    nico_swd, Nov 14, 2006 IP
  8. Robert Allen

    Robert Allen Peon

    Messages:
    2,685
    Likes Received:
    247
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Nice script, but unregistered users can download. I didnt login and i could download the file.

    Any fix ideas?

    Rob
     
    Robert Allen, Nov 16, 2006 IP
  9. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #9
    Try replacing this.
    
    if ($vbulletin->userinfo['posts'] >= MIN_POSTS)
    
    PHP:
    with this.
    
    if ($vbulletin->userinfo['userid'] != 0 AND $vbulletin->userinfo['posts'] >= MIN_POSTS)
    
    PHP:
     
    nico_swd, Nov 16, 2006 IP
  10. Robert Allen

    Robert Allen Peon

    Messages:
    2,685
    Likes Received:
    247
    Best Answers:
    0
    Trophy Points:
    0
    #10
    Here is the file which i am testing: www.mfa101.com/test.php

    I have edited that line, and guests can still download, as you can see. It is in the root directory of vBulletin.

    Thanks for all the help mate, I tryed to add more rep but.. "You need you spread more rep around before giving it to nico_swd again"

    Rob
     
    Robert Allen, Nov 16, 2006 IP