2014-02-06 4 views
0

저는 cURL을 처음 사용하기 때문에 귀하의 도움이 필요합니다. 제 상황은 form-site (form.php)를 통해 form (formular.php)을 보내고 싶습니다.PHP curl이 양식의 게시물 데이터를 보내지 않습니다.

form.php는 cURL을 통해 formular.php를 호출합니다.

<?php 
    error_reporting(-1); 
    $url = 'http://localhost/formular.php'; 
    $data = array('customerline' => 'nummer1', 'customerphonenumber' => 'nummer2'); 
    $postString = http_build_query($data, '', '&'); 
    $ch = curl_init(); 
    curl_setopt ($ch, CURLOPT_URL, $url); 
    curl_setopt ($ch, CURLOPT_POST, 2); 
    curl_setopt ($ch, CURLOPT_POSTFIELDS, $postString); 
    curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); 
    $post = curl_exec ($ch); 
    curl_close ($ch); 
    echo $post; 
?> 

formular.php

<?php if(isset($_POST['form'])): ?> 
    Sent! 
<?php else: ?> 
    <form action="http://localhost/formular.php" method="post" name="form"> 
     <input type="text" name="customerline" /> 
     <input type="text" name="customerphonenumber" /> 
     <input type="submit" value="send" name="form" /> 
    </form> 
<?php endif; ?> 

내 문제는 방법을 이해하지 않습니다이다 form.php : 여기

은 모두 소스 코드입니다 "Sent!"텍스트 통로를 얻으십시오.

도와 주시겠습니까?

답변

1

옵션에 대한

$url = 'http://localhost/formular.php'; 
$data = array('customerline' => 'nummer1', 'customerphonenumber' => 'nummer2'); 
$ch = curl_init(); 
curl_setopt ($ch, CURLOPT_URL, $url); 
curl_setopt ($ch, CURLOPT_POST, true); 
curl_setopt ($ch, CURLOPT_POSTFIELDS, $data); 
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); 
$post = curl_exec ($ch); 
curl_close ($ch); 
echo $post; 

더 많은 정보를 원하시면.

추가해야합니다. 따라서 게시자 매개 변수는 다음과 같아야합니다.

$data = array(
    'customerline' => 'nummer1', 
    'customerphonenumber' => 'nummer2', 
    'form' => 'value' 
); 
+0

입력에 감사드립니다. 이제 완벽하게 작동합니다. 손 들어 (: –

2

배열을 쿼리 문자열로 변환하지 않고 직접 전달할 수 있습니다. CURLOPT_POSTtrue이어야합니다.

보십시오 : 당신은 형태 if(isset($_POST['form']))에 있지만, 당신이 그것을 전송되지 않습니다 컬의 값을 가지고 귀하의 경우 조건에 기대 http://my1.php.net/curl_setopt

관련 문제