Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>For the absolute best security you would need some communication from <code>server 2</code> to <code>server 1</code>, to double check if the request is valid. Although this communication could be minimal, its still communication and thus slows down the proces. If you could live with a marginally less secure solution, I would suggest the following.</p> <p>Server 1 requestfile.php:</p> <pre><code>&lt;?php //check login if (!$loggedon) { die('You need to be logged on'); } $dataKey = array(); $uniqueKey = 'fgsdjk%^347JH$#^%&amp;5ghjksc'; //choose whatever you want. //check file $file = isset($_GET['file']) ? $_GET['file'] : ''; if (empty($file)) { die('Invalid request'); } //add user data to create a reasonably unique fingerprint. //It will mostlikely be the same for people in the same office with the same browser, thats mainly where the security drop comes from. //I double check if all variables are set just to be sure. Most of these will never be missing. if (isset($_SERVER['HTTP_USER_AGENT'])) { $dataKey[] = $_SERVER['HTTP_USER_AGENT']; } if (isset($_SERVER['REMOTE_ADDR'])) { $dataKey[] = $_SERVER['REMOTE_ADDR']; } if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) { $dataKey[] = $_SERVER['HTTP_ACCEPT_LANGUAGE']; } if (isset($_SERVER['HTTP_ACCEPT_ENCODING'])) { $dataKey[] = $_SERVER['HTTP_ACCEPT_ENCODING']; } if (isset($_SERVER['HTTP_ACCEPT'])) { $dataKey[] = $_SERVER['HTTP_ACCEPT']; } //also add the unique key $dataKey[] = $uniqueKey; //add the file $dataKey[] = $file; //add a timestamp. Since the request will be a different times, dont use the exact second //make sure its added last $dataKey[] = date('YmdHi'); //create a hash $hash = md5(implode('-', $dataKey)); //send to server 2 header('Location: https://server2.com/download.php?file='.urlencode($file).'&amp;key='.$hash); ?&gt; </code></pre> <p>On server 2 you will do almost the same.</p> <pre><code>&lt;?php $valid = false; $dataKey = array(); $uniqueKey = 'fgsdjk%^347JH$#^%&amp;5ghjksc'; //same as on server one //check file $file = isset($_GET['file']) ? $_GET['file'] : ''; if (empty($file)) { die('Invalid request'); } //check key $key = isset($_GET['key']) ? $_GET['key'] : ''; if (empty($key)) { die('Invalid request'); } //add user data to create a reasonably unique fingerprint. if (isset($_SERVER['HTTP_USER_AGENT'])) { $dataKey[] = $_SERVER['HTTP_USER_AGENT']; } if (isset($_SERVER['REMOTE_ADDR'])) { $dataKey[] = $_SERVER['REMOTE_ADDR']; } if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) { $dataKey[] = $_SERVER['HTTP_ACCEPT_LANGUAGE']; } if (isset($_SERVER['HTTP_ACCEPT_ENCODING'])) { $dataKey[] = $_SERVER['HTTP_ACCEPT_ENCODING']; } if (isset($_SERVER['HTTP_ACCEPT'])) { $dataKey[] = $_SERVER['HTTP_ACCEPT']; } //also add the unique key $dataKey[] = $uniqueKey; //add the file $dataKey[] = $file; //add a timestamp. Since the request will be a different times, dont use the exact second //keep the request time in a variable $time = time(); $dataKey[] = date('YmdHi', $time); //create a hash $hash = md5(implode('-', $dataKey)); if ($hash == $key) { $valid = true; } else { //perhaps the request to server one was made at 2013-06-26 14:59 and the request to server 2 come in at 2013-06-26 15:00 //It would still fail when the request to server 1 and 2 are more then one minute apart, but I think thats an acceptable margin. You could always adjust for more margin though. //drop the current time $requesttime = array_pop($dataKey); //go back one minute $time -= 60; //add the time again $dataKey[] = date('YmdHi', $time); //create a hash $hash = md5(implode('-', $dataKey)); if ($hash == $key) { $valid = true; } } if ($valid!==true) { die('Invalid request'); } //all is ok. Put the code to download the file here ?&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload