我有一个包含变量的URL的“谢谢”页面:
http://vieillemethodecorpsneuf.com/confirmation-achat-1a/?item=1&cbreceipt=VM6JQ6VE&time=1429212702&cbpop=C123FA24&cbaffi=twitpalace&cname=Roberto+Laplante&cemail=roberto%40gmail.com&ccountry=FR&czip=000
我有一个GET函数来捕获变量:
<?php
$clickbank_name = (isset($_GET['cname'])) ? $_GET['cname'] : '';
$clickbank_email = (isset($_GET['cemail'])) ? $_GET['cemail'] : '';
$clickbank_country = (isset($_GET['ccountry'])) ? $_GET['ccountry'] : '';
$clickbank_zip = (isset($_GET['czip'])) ? $_GET['czip'] : '';
$clickbank_aff = (isset($_GET['cbaffi'])) ? $_GET['cbaffi'] : '';
?>现在,我需要使用curl将数据发送到Zapier URL (但是它附带了变量,因此它将给我提供):
ps。我在URL中添加了一个手动标记
用什么PHP Curl代码来实现这个工作呢?必须在现场行动的背后。
发布于 2015-05-05 04:55:40
我试试看。
$get_fields = ['tag' => 'client'];
if (isset($_GET['cname'])) $get_fields['cname'] = $_GET['cname'];
if (isset($_GET['cemail'])) $get_fields['cemail'] = $_GET['cemail'];
if (isset($_GET['ccountry'])) $get_fields['ccountry'] = $_GET['ccountry'];
if (isset($_GET['czip'])) $get_fields['czip'] = $_GET['czip'];
if (isset($_GET['cbaffi'])) $get_fields['cbaffi'] = $_GET['cbaffi'];
$encoded = '';
foreach($get_fields as $name => $value){
$encoded .= urlencode($name).'='.urlencode($value).'&';
}
$url = 'https://zapier.com/hooks/catch/bheq6y/?'.rtrim($encoded,'&');
// simple get curl
$output = file_get_contents($url);
// or if you want more control over the request
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => $url,
));
$output = curl_exec($curl);
curl_close($curl);发布于 2015-10-15 06:39:22
在本例中,我们将参数中的数据提交到另一个curl.php页面,在curl.php中,我编写了一些代码,以便每当调用curl.php时执行,结果将从curl.php收到请求的地方发送回页面。机制:此示例是在PHP中使用Curl创建的。
第一步:创建curl.php文件。该文件将由另一个php文件使用curl机制调用。所以在curl.php中我们将得到一些参数。我们得到了参数,并做了一些功能。之后,当我们想要输出时,我们只需使用json_encode()和简单回显对json进行编码。
$post = $_POST;
echo json_encode($post);注意: index.php将以json格式获取数据,因为我们要将json格式的数据发送回index.php。
第二步:我们必须创建一个index.php文件。其中,我们用一些参数编写一个执行卷曲的逻辑,然后调用curl.php并从curl.php $url =‘demo/curl.php’获得结果;//这是我希望在curl执行$ch =curl_init($url)时执行的目标文件(curl.php);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, 'id=1&name=sanjay'); // pass parameters to curl.php
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
$resArr = json_decode($response, true);
curl_close($ch);
print_r($resArr);注意:在curl成功执行后得到的数据,我们将以json格式获得。这意味着我们必须在php中使用json_decode()对其进行解码。
https://stackoverflow.com/questions/30044176
复制相似问题