AWS SDK V3 – S3 signed url – Laravel

$s3Client = \App::make(‘aws’)->createClient(‘s3’);
$bucket =[bucket name];
$key = [file name];
$command = $s3Client->getCommand(‘GetObject’, array(
‘Bucket’ => $bucket,
‘Key’ => $key,
‘ResponseContentDisposition’ => ‘attachment; filename="’.$key.’"’,
));
$request = $s3Client->createPresignedRequest($command, ‘+10 minutes’);
$signedUrlCannedPolicy = (string) $request->getUri();
echo "singed s3 url =>".$signedUrlCannedPolicy;

Note : you should have configured the s3 access key and secret key in config/aws.php

Advertisements

IP based restriction behind the load balance (proxy)

To restrict the access by IP’s through apache

RewriteEngine On
RewriteCond %{HTTP:X-Forwarded-For} !^192\.168\.0\.1
RewriteCond %{HTTP:X-Forwarded-For}!^192\.168\.0\.2
RewriteRule ^(.*)$ http://google.com/ [R=302]

 

by  PHP code you do it as follow,

if ($_SERVER[‘HTTP_X_FORWARDED_FOR’])
{
$ip = $_SERVER[‘HTTP_X_FORWARDED_FOR’];
}
else
{
$ip = $_SERVER[‘REMOTE_ADDR’];
}
$clip = explode(‘,’,$ip);
$ips = array(“xx.xx.xx.xx”,”xx.xx.xx.xx”);
$found =0;
foreach($clip as $sip)
{
if (in_array($sip, $ips))
{
$found++;
}
}
if(!$found)
{
die(“location.href = ‘http://www.google.com‘”);
}