2016-03-04 68 views
-2

PHP捲曲後不工作..PHP捲曲後場不工作

這裏是我的代碼

function post_to_url($url, $data) { 
    $fields = ''; 
    foreach($data as $key => $value) { 
     $fields .= $key . '=' . $value . '&'; 
    } 
    rtrim($fields, '&'); 

    $post = curl_init(); 

    curl_setopt($post, CURLOPT_URL, $url); 
    curl_setopt($post, CURLOPT_POST, count($data)); 
    curl_setopt($post, CURLOPT_POSTFIELDS, $fields); 
    curl_setopt($post, CURLOPT_RETURNTRANSFER, 1); 

    $result = curl_exec($post); 

    curl_close($post); 
} 

post_to_url("http://www.i-autosurf.com/signup.php",$data); 

可以請你籤的錯誤..

是腳麻或代碼網站有什麼不同嗎?

+0

'$ fields'也允許一個數組 – Neat

+0

真的???????? – learningpython

+1

爲了將來的參考,添加你的錯誤,並告訴你你已經嘗試做什麼 - 不要只是要求調試和代碼 – KDOT

回答

1

您可以按原樣傳遞數組。使用嘗試

function post_to_url($url, $fields) { 
    $post = curl_init($url); 

    curl_setopt($post, CURLOPT_POST, true); 
    curl_setopt($post, CURLOPT_POSTFIELDS, $fields); 
    curl_setopt($post, CURLOPT_RETURNTRANSFER, 1); 

    $result = curl_exec($post); 

    curl_close($post); 
} 
+0

不工作的傢伙!我沒有收到確認郵件 – learningpython

+0

$ data = array( 「name」=>「learningphp」, 「email1」=>「[email protected]」, 「email2」=>「[email protected] 「, 」passwd「=>」anything「, 」sitename「=>」anything「, 」url「=>」anything.com「, 」termscheck「=>」0「 ); – learningpython

+0

exec後顯示'$ result'中的內容。 – ksimka

0

試試這個

$postfields = http_build_query($data); 
$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL,$url); 
curl_setopt($ch, CURLOPT_POST, true); 
curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
+0

不工作我沒有收到確認郵件 – learningpython

+0

試着設置這個選項也curl_setopt($ ch,CURLOPT_SSL_VERIFYPEER,false);如果這有幫助 – Indrajit