小编Ste*_*ugh的帖子

检查Amazon s3签名URL上是否存在文件

我为Amazon s3创建了一个签名的$ URL,它在浏览器中完美打开.

http://testbucket.com.s3.amazonaws.com/100-game-play-intro-1.m4v?AWSAccessKeyId=AKIAJUAjhkhkjhMO73BF5Q&Expires=1378465934&Signature=ttmsAUDgJjCXepwEXvl8JdFu%2F60%3D
Run Code Online (Sandbox Code Playgroud)

**此示例中更改了存储桶名称和访问密钥

然而,我试图使用下面的函数来检查(使用curl)该文件是否存在.它未通过CURL连接.如果我用s3之外的图像的url替换上面的$ URL,那么这段代码可以完美地运行.

我知道该文件存在于亚马逊中,但如果使用如上所述的签名网址,则无法解决为什么此代码失败

有任何想法吗?

谢谢

这是我的代码.

function remoteFileExists($url) {

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, false);
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

    //don't fetch the actual file, only get header to check if file exists
    curl_setopt($ch, CURLOPT_HEADER, 1);
    curl_setopt($ch, CURLOPT_NOBODY, true);

    $result = curl_exec($ch);
    curl_close($ch);



    if ($result !== false) {

        $statusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);  

        if ($statusCode == 200) {
            $ret = true;   
        } else {
            $ret = false;
        }

    } else {
        $ret='connection failed';
    }

    return …
Run Code Online (Sandbox Code Playgroud)

php curl amazon-s3 amazon-web-services

5
推荐指数
1
解决办法
2390
查看次数

如何使用CURL获取HTTPS的正文内容

以下代码将检索在PHP中使用CURL而不是https检索的URL的正文内容.任何人都可以告诉我如何编辑代码,因为我需要返回的数据不仅仅是标题.

从我在这里做的测试是结果.你可以看到它有内容长度,我只是不知道如何访问它.

谢谢Stephen

错误:0

string(1457)"HTTP/1.1 200 OK日期:星期六,2009年8月1日06:32:11 GMT服务器:Apache/1.3.41(达尔文)PHP/5.2.4 mod_ssl/2.8.31 OpenSSL/0.9.7l缓存 - 控制:max-age = 60到期:周六,2009年8月1日06:33:11 GMT最后修改日期:2006年11月23日星期四17:44:53 GMT ETag:"97d620-44b-4565de15"接受范围:字节内容-Length:1099连接:关闭内容类型:text/html"

<?php

$curl_handle=curl_init();

$username = "";
$password = "";

$fullurl = "http://www.queensberry.com";
   $ch = curl_init();
   curl_setopt($ch, CURLOPT_HEADER, 1);
   curl_setopt($ch, CURLOPT_VERBOSE, 1);
   curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
   curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
   curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
   curl_setopt($ch, CURLOPT_FAILONERROR, 0);
   curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
   curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");
   curl_setopt($ch, CURLOPT_URL, $fullurl);

   $returned = curl_exec($ch);

   curl_close ($ch);
   var_dump($returned);


?>
Run Code Online (Sandbox Code Playgroud)

php https curl

3
推荐指数
1
解决办法
2万
查看次数

将nohup的输出错误发送到syslog

我正在尝试编写一个使用nohup的bash脚本并将错误传递给rsyslog.

我已尝试使用日志变量的不同变体(见下文),但无法将输出传递给除std txt文件之外的任何内容.我无法得到管道.

nohup imageprocessor.sh > "$LOG" &
Run Code Online (Sandbox Code Playgroud)

是否可以管道nohup输出或我需要一个不同的命令.

我尝试过的几种日志变体

LOG="|/usr/bin/logger -t workspaceworker -p LOCAL5.info &2"
Run Code Online (Sandbox Code Playgroud)

要么

LOG="|logtosyslog.sh"
Run Code Online (Sandbox Code Playgroud)

要么

LOG="logtosyslog.sh"
Run Code Online (Sandbox Code Playgroud)

bash nohup rsyslog

3
推荐指数
1
解决办法
3043
查看次数

这个403错误重定向有什么问题

您已经为joomla创建了一个error.php,以将404错误重定向到joomla文章.下面的代码适用于404错误,但403返回空白页面.我可以直接导航到我脚本之外的页面,因此它必须是我的代码或它在环境中的交互方式.

谢谢Stephen

defined( '_JEXEC' ) or die( 'Restricted access' );
if ($this->error->code == 404)
{
Header( "HTTP/1.1 404 Not found" );
header("Location: http://www.queensberry.com/misc/filenotfound/");
} else if ($this->error->code == 403) {
Header( "HTTP/1.1 403 Restricted Content" );
Header( "Location: http://www.queensberry.com/restrictedcontent/" ); 
} else {
echo "hello world error code = " . $this->error->code;
}
?>
Run Code Online (Sandbox Code Playgroud)

php joomla webserver http-status-code-403 http-status-code-404

1
推荐指数
2
解决办法
7398
查看次数