Jump to content

Redirect by passing variables


speedo

Recommended Posts

I have been at this all day - trying to redirect the user to download a file based on a PHP generated URL. It generates the URL fine, but I cannot for the life of me get the browser to redirect I tried doing header ("Location: $url") and also fopen - I'm just not skilled enough as I keep getting errors. Can someone please have a look and provide me with some methods for achieving this? $signedurl is the authenticated URL that the user needs to be directed to.

 

<?php
require_once('Crypt/HMAC.php');

function getS3Redirect($bucketName, $objectName)
{ 

$accessKey = "...LHGAQ"; 
$secretKey = "...VtWDKLb"; 
$S3_URL = "http://" . $bucketName . ".s3.amazonaws.com"; 
$expires = time() + (60*5); 
$stringToSign = "GET\n\n\n" . $expires . "\n/" . $bucketName . $objectName; 
$hasher = new Crypt_HMAC($secretKey, "sha1"); 
$sig = $hasher->hash(trim($stringToSign)); 
$sig = hex2b64($sig); 
$sig = rawurlencode(trim($sig)); 

$signedurl = "$S3_URL$objectName?AWSAccessKeyId=$accessKey&Expires=$expires&Signature=$sig";
$hrefString ="<a href= \"$signedurl\">$signedurl </a>";

return "$signedurl"; 

} 

// 
// 
function hex2b64($str) 
{ 
$raw = ''; 
for ($i=0; $i < strlen($str); $i+=2) 
{ 
$raw .= chr(hexdec(substr($str, $i, 2))); 
} 
return base64_encode($raw); 
} 
?>

<html>
<head>
<title>Untitled Document</title>
</head>
<body>
<p><?php
$bucketName = $_GET['bucket'];
$objectName = $_GET['object'];
echo getS3Redirect($bucketName, $objectName);
  ?></p>
  
</body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/205595-redirect-by-passing-variables/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.