Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 8 of 8
  1. #1
    Junior Member
    Join Date
    Jan 2021
    Location
    Coastal South Carolina, USA
    Posts
    4
    Member #
    62403

    How do I have download button point to mirrored site

    My website has a mirror of the download directory in the U.K.. On my download page I have 2 buttons, one for a U.S. download and one for a U.K. download. The current download page passes the filename to the download script. The download script (located in the download directory) for the U.S. download reads as follows:
    HTML Code:
    <?php
    
    $php_scripts = '../../php/';
    require $php_scripts . 'PDO_Connection_Select.php';
    require $php_scripts . 'GetUserIpAddr.php';
    function mydloader($l_filename=NULL)
    
    {
    $ip = GetUserIpAddr();
    if (!$pdo = PDOConnect("foxclone_data"))
    {	
        exit;
    }
        if( isset( $l_filename ) ) {  
            header('Content-Type: octet-stream');
            header("Content-Disposition: attachment; filename={$l_filename}");
            header('Pragma: no-cache');
            header('Expires: 0');        
            readfile($l_filename);
    
            $ext = pathinfo($l_filename, PATHINFO_EXTENSION);
            $stmt = $pdo->prepare("INSERT INTO download (address, filename,ip_address) VALUES (?, ?, inet_aton('$ip'))");
            $stmt->execute([$ip, $ext]) ; 
    
            $test = $pdo->query("SELECT lookup.id FROM lookup WHERE inet_aton('$ip') >= lookup.ipstart AND inet_aton('$ip') <= lookup.ipend");
            $ref = $test->fetchColumn();
            $ref = intval($ref);
    
            $stmt = $pdo->prepare("UPDATE download SET lookup_id = '$ref' WHERE address = '$ip'");
            $stmt->execute() ;         
          }
            
        else {
            echo "isset failed";
            }  
    }
    mydloader($_GET["f"]);
    exit;
    How do I modify it to download from the mirrored download directory if they select the U.K. download button. I think the download page will need to point to a separate download script for the U.K. download, but I'm not sure how to code it.

    Additional info: The originating website is https://foxclone.com, the mirror is https://foxclone.org

    Would the following work as a separate script for the U.K. download?

    HTML Code:
    <?php
    $php_scripts = '../../php/';
    require $php_scripts . 'PDO_Connection_Select.php';
    require $php_scripts . 'GetUserIpAddr.php';
    function mydloader($l_filename=NULL)
    
    {
    $ip = GetUserIpAddr();
    if (!$pdo = PDOConnect("foxclone_data"))
    {	
        exit;
    }
        if( isset( $l_filename ) ) {  
            <a href="https://foxclone.org/download/?" download={$l_filename}></a>
    
            $ext = pathinfo($l_filename, PATHINFO_EXTENSION);
            $stmt = $pdo->prepare("INSERT INTO download (address, filename,ip_address) VALUES (?, ?, inet_aton('$ip'))");
            $stmt->execute([$ip, $ext]) ; 
    
            $test = $pdo->query("SELECT lookup.id FROM lookup WHERE inet_aton('$ip') >= lookup.ipstart AND inet_aton('$ip') <= lookup.ipend");
            $ref = $test->fetchColumn();
            $ref = intval($ref);
    
            $stmt = $pdo->prepare("UPDATE download SET lookup_id = '$ref' WHERE address = '$ip'");
            $stmt->execute() ;         
          }
            
        else {
            echo "isset failed";
            }  
    }
    mydloader($_GET["f"]);
    exit;
    TIA
    Last edited by larry29936; Jan 21st, 2021 at 10:47 AM. Reason: Additional Info & possible solution

  2.  

  3. #2
    WDF Staff mlseim's Avatar
    Join Date
    Apr 2004
    Location
    Cottage Grove, Minnesota
    Posts
    7,966
    Member #
    5580
    Liked
    757 times
    Do you just have two domain names pointing to the same physical website?
    So you have one website and one SQL database?

    Or are these two separate websites on two different webhosts?

    PS: The foxclone.org site does not load.

    Also, what is the purpose for having the .com and .org as it pertains to U.S. or U.K.?
    Last edited by mlseim; Jan 21st, 2021 at 11:06 AM.


  4. #3
    Junior Member
    Join Date
    Jan 2021
    Location
    Coastal South Carolina, USA
    Posts
    4
    Member #
    62403
    Thanks for the quick reply. These are two separate websites on two different webhosts. The .org website isn't up yet. The reason we're doing this is that folks in Europe are sometimes getting incomplete downloads from the U.S. host. The .org host is in the U.K.
    Last edited by larry29936; Jan 21st, 2021 at 11:16 AM.

  5. #4
    WDF Staff mlseim's Avatar
    Join Date
    Apr 2004
    Location
    Cottage Grove, Minnesota
    Posts
    7,966
    Member #
    5580
    Liked
    757 times
    If the two sites are separate and each one has their own SQL database with the data duplicated in both sites, then it should not matter. The sites are totally separate and unrelated, except for the fact that you (the admin) keeps both of them updated with the same information. The same scripts should work the same on both sites.

    There might be a spot somewhere in the config files where you enter the "parent" domain name. Or maybe not ... the scripts might be using relative paths where the domain name is not really relative.

    It would be no different than if I duplicated your website and all files on my website. It would operate just the same as your site. Nobody would know the difference unless they found out they were hosted on different hosts.

    Now if you had the data (files) stored in only ONE of the two websites, that would be different.

    Duplicate everything from your U.S. site to the U.K. site, including the SQL database, tables, and data. Everything should be just fine.


  6. #5
    Junior Member
    Join Date
    Jan 2021
    Location
    Coastal South Carolina, USA
    Posts
    4
    Member #
    62403

    Further explanation

    Maybe I didn't describe what I'm trying to accomplish clearly. When a user goes to the download page of the U.S. site, they have a choice of where to download from for each file, a button to download from the U.S. site and a button to download from the U.K. site. The sites are identical. Maybe an image of what it looks like for one of the files will help.
    Attached Images Attached Images

  7. #6
    WDF Staff mlseim's Avatar
    Join Date
    Apr 2004
    Location
    Cottage Grove, Minnesota
    Posts
    7,966
    Member #
    5580
    Liked
    757 times
    Essentially 'anyone' can make a link on their website to download your file. You can too, from either site.
    You have nothing to protect anyone (like me) from creating a link on my own site.
    Now if this is a problem, then you need to create a login or password to keep people like me from creating a link like I did.


    I think where you're getting stuck is the fact that your link looks like this:

    download/mydloader.php?f=foxclone42-04.iso


    When it could look like this:

    https://foxclone.com/download/mydloader.php?f=foxclone42-04.iso
    Last edited by mlseim; Jan 24th, 2021 at 01:38 PM.


  8. #7
    Junior Member
    Join Date
    Jan 2021
    Location
    Coastal South Carolina, USA
    Posts
    4
    Member #
    62403
    While I'm working on redesign, I'll change the code so that I'm not passing a filename to mydloader.php, just an index number from the files table of the database. I'll do a query in mydloader.php to get the filename and do the download.

    Thanks for the assist.

  9. #8
    WDF Staff mlseim's Avatar
    Join Date
    Apr 2004
    Location
    Cottage Grove, Minnesota
    Posts
    7,966
    Member #
    5580
    Liked
    757 times
    Good idea. Make it like a key. In fact, use POST instead of GET and include another separate key that no user will ever see. Only the other script will see it and verify it came from your site, not anyone else's. People would still be able to use your site to get the files, but they would not be able to do what I did and create links on my own site. By using POST, you don't put variables in the URL. Look up 'PHP CURL POST tutorial'



Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 09:20 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com