2017-04-25 75 views
0

我有一个从mysql表中收集数据的while循环,将它们插入到php变量中。这些php变量作为参数传递给php函数中存在的url。显然,url不会选择php变量的值。需要帮助。代码看起来像这样。如何在一个url中传递php变量,存在于php函数中

<?php 
include('adodb/adodb.inc.php'); 
$link=mysql_connect("160.60.20.100","vcpm","abcd"); 
mysql_select_db("vcpm"); 

$GMT='2017-04-23 00:59'; 
$MinusOne='2017-04-23 00:00'; 

$query="SELECT fraud_id,stat_id from Hasoffers where fraud_id IS NOT NULL AND stat_datetime between '".$MinusOne."' AND '".$GMT."';"; 
$pl=mysql_query($query); 
$count=mysql_num_rows($pl); 

while($row=mysql_fetch_array($pl)) 
{ 
    $conversion_id=$row['stat_id']; 

    $fraud_category=$row['fraud_id']; 

    echo ip($conversion_id,$fraud_category).PHP_EOL; 
} 

function ip($conversion_id,$fraud_category) 
{ 
    $conversion_id= $argv[1]; 
    $fraud_category= $argv[2]; 

    $url="https://api.hasoffers.com/Apiv3/json?NetworkId=mxpresso&Target=Conversion&Method=updateMeta&NetworkToken=NETY5hP42BJX8KJlTmTQfsjTo1Rq1m&id=".$conversion_id."&data[note]=".$fraud_category; 
     echo $url; 

     // Initiate curl 
    $ch = curl_init(); 
    // Disable SSL verification 
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,false); 
    //Will return the response, if false it print the response 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER,true); 
    // Set the url 
    curl_setopt($ch, CURLOPT_URL,$url); 
    // Execute 
    $result=curl_exec($ch); 
    // Closing 
    curl_close($ch); 
} 

?> 
+0

你可以分享你所得到的错误传递argumnents PHP脚本 $ argv的使用? –

+1

$ conversion_id = $ argv [1]; $ fraud_category = $ argv [2]; 这些是什么? 您可以通过名称直接在函数内部使用参数 –

+0

将它们作为参数在url中传递 –

回答

0

什么

curl_setopt($ch, CURLOPT_POSTFIELDS, 
     "NetworkId=mxpresso&Target=Conversion&........."); 

帮助?

+0

这只是一个疯狂的猜测,它应该是一个评论。 – arkascha

+0

也没有试过 –

0

这样的:

$conversion_id= $argv[1]; 
$fraud_category= $argv[2]; 

可能是您的问题。 当你想能够调用命令行see doc

你实际上是压倒一切的传递从MySQL的函数的参数页的阵列被使用,这就是问题所在。

注释两条线,并尝试呼应网址

0

以为你实现正确的URL/url变量名等,删除以下内容:

$conversion_id= $argv[1]; 
$fraud_category= $argv[2]; 

$ ARGV [1]/$的argv [2]覆盖您从提供的参数中获得的值。

0

在您的ip函数中,您正在使用$ argv 1和$ argv [2]重载$conversion_id$fraud _category。当你在命令行

PHP argv manual

请参阅本文档的argv $使用

相关问题