标签: curl

将变量传递给curl_setopt

我希望能够执行以下操作:

 $search_terms[0]='frank';
    $search_terms[1]='sinatra';
    $search_terms[2]='beyonce';

    foreach($search_terms as $term){
    $ch = curl_init();
    $url ='http://search.twitter.com/search.json?q=' + $term +'&rpp=100';
    curl_setopt($ch, CURLOPT_URL,$url);
    curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);

    $var = curl_exec($ch);


    curl_close($ch);

    $obj = json_decode($var, true);

echo $term;
    var_dump($obj);
    }
Run Code Online (Sandbox Code Playgroud)

但是当我转储 $obj 时,我得到一个 NULL 对象,即使 $term 打印正常。

php curl

0
推荐指数
1
解决办法
4909
查看次数

exec()、shell_exec()、curl_exec() 的安全漏洞

有时,我会使用 exec()、shell_exec() 和curl_exec()。以下是典型用途。假设其中有 PHP 变量(即第一个变量中的 $html),用户有可能修改其内容。

从安全漏洞的角度来看,我应该关注什么?escapeshellcmd() 和 escapeshellarg() 是答案吗?如果是,应该在哪里使用?

$cmd='echo "html + '.$html.'" | htmldoc --format pdf > '.$filename;
$cmd='/usr/bin/convert '.$docs.' '.$filename;
$cmd='HOME='.$dir.'; /usr/bin/libreoffice3.5 --headless -convert-to pdf --outdir '.$dir.' '.$file_org;
$cmd='wget -O '.$file_org.' "'.$url.'"';
$cmd='/opt/wkhtmltopdf/bin/wkhtmltopdf "'.$url.'" '.$paramaters;
$cmd='/usr/bin/php -q '.$worker.' '.$session_id.' >/dev/null &';
exec($cmd);

$cmd='sendfax -n -m -w -i '.$id.' -o JohnDoe -D -S "hello@gmail.net" -s "us-leg" -f "'.$from.'" -d "'.$to.'" '.$doc_list;
$cmd = "faxstat -s | grep \"^$jid \"";
$output = shell_exec($cmd);

$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_USERAGENT, …
Run Code Online (Sandbox Code Playgroud)

php security shell curl shell-exec

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

PHP:如何在一个页面上使用会话,而另一个带有会话的页面正在加载

我正在使用 CURL 从外部 url 下载一个大文件并将其保存在我的服务器上。这可能需要几分钟的时间。下载运行时,我使用curl_setopt($ch, CURLOPT_PROGRESSFUNCTION,.. 运行匿名函数,该函数定期使用当前下载信息更新我的 $_SESSION['download_progress'] 变量。

现在,所有这些都发生在 upload.php 文件中,当用户等待文件下载时,我使用 javascript 请求 Progress.php 页面,其中包含以下简单代码:

session_start();
echo $_SESSION['download_progress'];
Run Code Online (Sandbox Code Playgroud)

这允许我的 JavaScript 代码显示有关下载进度的信息。

除非它不起作用。

在“upload.php”完成加载之前,“progress.php”页面不会加载(换句话说,两个页面仅在文件下载完成后才加载),这不好。session_start() 以某种方式阻止“progress.php”页面加载。我使用自己的服务器(apache + php 5.4),所以我拥有所有管理权限。

我怎么解决这个问题?我可以使用一些丑陋的解决方法,例如将下载信息写入文本文件而不是会话变量,然后使用 javascript 直接读取该文本文件,但我宁愿不这样做。

谢谢

php curl session-variables progress

0
推荐指数
1
解决办法
1376
查看次数

使用 cURL 登录并保存会话

索引.php

<?php
if($_POST) {
    $url = 'http://127.0.0.1/login.php';
    $socks = '127.0.0.1:9999';
    $fields = 'password=' . $_POST['captcha'] . '';

    $ch = curl_init();

    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.22 (KHTML, like Gecko) Chrome/25.0.1364.172 Safari/537.22");
    //curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);
    //curl_setopt($ch, CURLOPT_PROXY, $socks);
    //curl_setopt($ch, CURLOPT_INTERFACE, 'eth0:12');
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_COOKIEFILE, "cookie.txt");
    curl_setopt($ch, CURLOPT_COOKIEJAR, "cookie.txt");
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
    curl_setopt($ch, CURLOPT_TIMEOUT, 3600);

    $result = curl_exec($ch);

    curl_close($ch);
}
?>
<form action="" method="POST">
    Password <input …
Run Code Online (Sandbox Code Playgroud)

php session curl

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

下载最新的 Firefox 版本脚本

如何通过命令行下载最新版本的 Firefox 并插入到脚本中

我努力了wget https://download.mozilla.org/?product=firefox-38.0.1-SSL&os=linux64&lang=en-US

我从https://www.mozilla.org/en-US/firefox/new/的下载按钮复制了链接位置

但是这个 wget 命令只是生成了一个无用的index.html?product=firefox-38.0.1-SSL文件,很可能是因为没有转义字符,但无论如何,这个命令都被限制为静态38版本,而不是通用的

wget http://wordpress.org/latest.tar.gz

curl通过curl -O https://wordpress.org/latest.tar.gz

或者这是不可能的,因为 Firefox 不提供最新的 tar 链接?有没有有效的解决方法?

apt-get install firefox也使用,但是 apt 存储库似乎不包含最新的 Firefox

firefox curl wget apt-get

0
推荐指数
1
解决办法
5833
查看次数

c++ 通过系统在shell中运行curl

如果我在 shell 中写下这个,一切都会像魅力一样工作:

// shell (unix)
curl -X PUT -d "{ \"string\" : \"my string 1212 \"}" "https://my.firebaseio.com/myVal.json"
Run Code Online (Sandbox Code Playgroud)

如您所知,这会在我的firebase. 如上所述,这按预期工作。由于我对 C++ 不太了解,所以我不知道如何curl在内部 PUT -requests。我正在考虑通过在 shell 中执行此操作system

我最终得到了这个:

// c++ code
system('curl -X PUT -d "{ \"string\" : \"my string 1212 \"}" "https://my.firebaseio.com/myVal.json" ');
Run Code Online (Sandbox Code Playgroud)

然而,这会产生以下输出:

curl: (6) Could not resolve host: 
curl: (6) Could not resolve host: CD
curl: (7) Could not resolve host: CD
curl: (3) [globbing] unmatched close brace/bracket in column 1
Run Code Online (Sandbox Code Playgroud)

感谢您提供任何有用的建议 …

c++ shell curl

0
推荐指数
1
解决办法
8055
查看次数

卷曲中的-v和-k是什么意思?

我读了这一整页

http://conqueringthecommandline.com/book/curl#cha-3_footnote-1

我没有看到任何cURL-v或选项-k

我有这个卷曲请求:

curl -v -k --user "bla/test@bla.com:BlaBla" \
    "theUrlToTheServer" | xmllint --format - > something.xml
Run Code Online (Sandbox Code Playgroud)

我开始尝试理解 do-v-kMean 的意思,但我无法理解它们,请你帮忙

curl http

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

如何使用 Laravel 和 PHP 将数据发送到 SOAP Web 服务

我尝试使用 Laravel 将 XML 空缺职位发送到 Web 服务,但我正在努力弄清楚如何连接到 Web 服务、授权和发送所需的数据。

我尝试过使用curl,但我得到了

错误:“” - 代码:0

下面是我的代码

$result // IS MY XML file

$username = 'username'
$password = 'password'
$URL = 'http://xxxxxx.com;

//setting the curl parameters.
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $URL);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS,"xmlRequest=" . $result);
curl_setopt($ch, CURLOPT_ENCODING, 'UTF-8');
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded'));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 30); //timeout after 30 seconds
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");
curl_exec($ch);

if(!curl_exec($ch)){
    die('Error: "' . curl_error($ch) . '" - Code: ' …
Run Code Online (Sandbox Code Playgroud)

php xml curl soap laravel

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

为什么我在 ip 而不是主机名上卷曲时需要额外的“-k”标志?

我有这个代码

$ curl  "https://api.weixin.qq.com:443/sns/jscode2session?appid=a&secret=b&js_code=c&grant_type=authorization_code"
Run Code Online (Sandbox Code Playgroud)

它可以从服务器获得如下响应

{"errcode":40013,"errmsg":"invalid appid rid: 5f96703e-5e24e4f1-691a9221"}
Run Code Online (Sandbox Code Playgroud)

但是,当我尝试将主机名替换为 ip 时,我失败并显示以下消息

$ host api.weixin.qq.com
api.weixin.qq.com has address 180.97.7.108
api.weixin.qq.com has address 101.226.212.27

$ curl  "https://101.226.212.27:443/sns/jscode2session?appid=a&secret=b&js_code=c&grant_type=authorization_code"
curl: (60) SSL: no alternative certificate subject name matches target host name '101.226.212.27'
More details here: https://curl.haxx.se/docs/sslcerts.html

curl failed to verify the legitimacy of the server and therefore could not
establish a secure connection to it. To learn more about this situation and
how to fix it, please visit the web page mentioned above. …
Run Code Online (Sandbox Code Playgroud)

https curl http

0
推荐指数
1
解决办法
370
查看次数

curl -xget 在 powershell 5.1 中出现错误

如您所见,curl -xget在 PS 7.2 和 cmd 中运行良好,但在 PS 5.1 中出现错误。

Invoke-WebRequest:找不到与参数名称“xget”匹配的参数。

我究竟做错了什么?

错误的屏幕截图,并排的 Powershell 窗口

windows powershell curl

0
推荐指数
1
解决办法
872
查看次数