2011-07-26 3 views
1

양식을 사용하여 기부금의 item_name과 금액을 페이지의 로컬 PHP 스크립트로 보내지 만, 스크립트는 paypal.com으로 보내며 기부 페이지는 보내지 않습니다. 나는 아무것도 잘못 보는 것이 아니라 모두 체크 아웃하지만 그 일을하지는 않습니다.cURL 및 Paypal이 작동하지 않습니다.

가 가
<form action="http://example.net/beta/index.php" method="post" class="payPalForm" id="paypal"> 
     <div> 
        <div class="formRow"> 
        <div class="hidden" id="error" style="width:100%"><h3> I'm sorry, that STEAM ID you entered was incorrect.</h3></div> 
         </div> 
       <div class="formRow"> 

       <label for="field0"> 
        Steam ID<span class="star">*</span>:    </label> 
             <input type="text" name="item_name" id="item_name" class="textField required" /> 

       </div> 


       <div class="formRow"> 

       <label for="field2"> 
        Amount:    </label> 

         <select name="amount" id="field2" class="select">      
                 <option value="5">$5</option> 
                  <option value="10">$10</option> 
                  <option value="15">$15</option> 
                  <option value="20">$20</option> 
                  <option value="25">$25</option> 
                  <option value="30">$30</option> 
                  <option value="35">$35</option>                
         </select> 

       </div> 

      <div class="formRow"> 
      <input type="submit" value="Donate" id="donatebtn" onclick="return verifySteamID()" /> 
     </div> 
</form> 
이 그렇지 않으면 paypal.com에 갈 수 없을 것 그것은 스크립트로 보내 않습니다

그 언급되지 않기 때문에 : 그것은 전송

<?php 
    function datapost($URLServer,$postdata) 
    { 
    $agent = "Mozilla/5.0"; 

    $cURL_Session = curl_init(); 

    curl_setopt($cURL_Session, CURLOPT_URL,$URLServer); 

    curl_setopt($cURL_Session, CURLOPT_USERAGENT, $agent); 

    curl_setopt($cURL_Session, CURLOPT_POST, 1); 

    curl_setopt($cURL_Session, CURLOPT_POSTFIELDS,$postdata); 

    curl_setopt($cURL_Session, CURLOPT_RETURNTRANSFER, 1); 

    curl_setopt($cURL_Session, CURLOPT_FOLLOWLOCATION, 1); 

    $result = curl_exec ($cURL_Session); 

    } 



    $htmlsource= datapost("https://www.paypal.com/cgi-bin/webscr","cmd=_donations&[email protected]&notify_url=http://example.net/donate/paypal.php?action=ipn&return=http://example.net/donate/thankyou.php&rm=2&no_note=1&cbt=Back&no_shipping=1&lc=US&currency_code=USD&item_name=".$_POST['item_name']."&amount=".$_POST['amount']."&bn=PP-DonationsBF:btn_donate_LG.gif:NonHostedGuest"); 
    ?> 

그리고 형태 : 다음은 로컬 스크립트입니다 다른 곳. 왜 작동하지 않는지, 어떤 생각인지 이해가 안되니?

+0

아무도 없습니까? 한 사람 아니야?! – Harry

답변

0

이 문제가 여전히 발생하는 지 확실하지 않은 경우 일부 시나리오에서 CURLOPT_FOLLOWLOCATION이 예상대로 수행되지 않는 것으로 나타났습니다. 이것은 대개 서버 구성 문제 일 뿐이지 만 쉽게 변경할 수있는 사항이 아닙니다.

function curl_redir_exec($ch,$test = false) 
    { 
    static $curl_loops = 0; 
    static $curl_max_loops = 20; 
    if ($curl_loops++>= $curl_max_loops) 
    { 
    $curl_loops = 0; 
    return FALSE; 
    } 
    curl_setopt($ch, CURLOPT_HEADER, true); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
    $data = curl_exec($ch); 
    list($header, $data) = explode("\n\n", $data, 2); 
    $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); 
    if ($http_code == 301 || $http_code == 302) 
    { 
    $matches = array(); 
    preg_match('/Location:(.*?)\n/', $header, $matches); 
    $url = @parse_url(trim(array_pop($matches))); 
    if (!$url){ 
     //couldn't process the url to redirect to 
     $curl_loops = 0; 
     return $data; 
    } 
    $last_url = parse_url(curl_getinfo($ch, CURLINFO_EFFECTIVE_URL)); 
    if (!$url['scheme']) 
    $url['scheme'] = $last_url['scheme']; 
    if (!$url['host']) 
    $url['host'] = $last_url['host']; 
    if (!$url['path']) 
     $url['path'] = $last_url['path']; 
     $new_url = $url['scheme'] . '://' . $url['host'] . $url['path'] . ($url['query']?'?'.$url['query']:''); 
     curl_setopt($ch, CURLOPT_URL, $new_url); 
     return $this->curl_redir_exec($ch); 
    } else { 
     $curl_loops=0; 
     if($test){ 
      return curl_getinfo($ch, CURLINFO_EFFECTIVE_URL).'<br />'.$http_code.'<br />'.$data; 
     }else{ 
      return curl_getinfo($ch, CURLINFO_EFFECTIVE_URL); 
     } 
    } 
} 

function curl_post_fields($array){ 
    foreach ($array as $key=>$value){ 
     $arr_output[] = trim($key).'='.trim($value); 
    } 
    return preg_replace('#(\r\n|\r|\n)+#m',"",trim(implode('&', $arr_output))); 
} 

전체 CURL 호출은이처럼 보이는 :

$data2 = $fn->curl_post_fields($data1); 
$curl_session = curl_init($url); 
curl_setopt($curl_session, CURLOPT_URL, $url); 
curl_setopt($curl_session, CURLOPT_COOKIESESSION, 1); 
curl_setopt($curl_session, CURLOPT_FRESH_CONNECT, 1); 
curl_setopt($curl_session, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-GB;) Firefox/3.6.13"); 
curl_setopt($curl_session, CURLOPT_HTTPHEADER, array('X-Forwarded-For: '.$_SERVER['REMOTE_ADDR'])); 
curl_setopt($curl_session, CURLOPT_VERBOSE, 1); 
curl_setopt($curl_session, CURLOPT_POST, 1); 
curl_setopt($curl_session, CURLOPT_POSTFIELDS, $data2); 
curl_setopt($curl_session, CURLOPT_TIMEOUT, 30); 
curl_setopt($curl_session, CURLOPT_SSL_VERIFYPEER, FALSE); 
$redirect_url = $shop->curl_redir_exec($curl_session); 
if(curl_errno($curl_session)) 
{ 
    echo '<p>An error has occurred, please take note of the information below and contact support.</p>'; 
    echo "<br>Errno : ".curl_errno($curl_session) ."<br>"; 
    echo "<br>Error : ".curl_error($curl_session) ."<br>"; 
    die(); 
} 
curl_close($curl_session); 
header("location:$redirect_url"); 

우리가 기능을 쓴이 문제를 해결하려면 (아래)는 CURL 전화와 결합하는 우리에게 우리가 필요로하는 솔루션을 준

이 정보가 도움이되기를 바랍니다.