2016-08-18 6 views
0

これは、カスタムフィールドを使用してPayPal IPNにセッション変数を渡す必要があるためです。 (少なくとも、IPNに変数セッションを渡すことを考えた唯一の解決策でした)アクションリンクに行く前にフォームフィールドを検証する

ブラウザのinspect要素を使用して誰もidを別のidに変更しないかどうかを確認する必要があります。あなたが見ることができるように、私はすでに以下のif文を持っており、アクションリンクを削除すると動作しますが、フォームアクションが設定されているので、if set文を実行しません。だから問題は、アクションリンクを削除せずに、またはフォームフィールドに行く前にフォームフィールドを検証するにはどうすればいいですか?

これができない場合は、そうすることができますか? (あるいは少なくとも、HTMLにIDを表示せずにセッション変数をPayPal IPNに渡す方法はありますか?)

これを動作させようとするのはほぼ2日間でした。

... 
<?php 
    if (isset($_POST['submit'])) { 
     if ($_POST['custom'] == $_SESSION['id']) { 
      header('Location: https://www.sandbox.paypal.com/cgi-bin/webscr'); // This is what I tried but no success. (I did remove the action link when I added this) 
     } else { 
      header('Refresh: 0'); 
     } 
    } 
?> 
<form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post" target="_top"> <!-- I want it to verify first if the $_POST['custom'] is equal to the $_SESSION['id'] before it goes to the PayPal website.--> 
<input type="hidden" name="cmd" value="_s-xclick"> 
<input type="hidden" name="hosted_button_id" value="*********"> 
<table> 
    <tr> 
     <td> 
      <input type="hidden" name="on0" value="Items">Items 
     </td> 
    </tr> 
    <tr> 
     <td> 
      <select name="os0"> 
       <option value="Item1">Item1 $1.00 USD</option> 
       <option value="Item2">Item2 $2.00 USD</option> 
      </select> 
     </td> 
    </tr> 
</table> 
<input type="hidden" name="currency_code" value="USD"> 
<input type="hidden" name="custom" value="<?php echo $_SESSION['id']; ?>"/> 
<input type="submit" name="submit" value="Buy now" /> 
</form> 
?> 
... 
+0

私は、彼らがソースコード内で見ることができるものとして、ユーザのセッションを持っていないでしょう。フォームは、サーバー上の別のページに送信して、paypalに送信する前にセッション情報を追加することができます。 – Nick

答えて

0

サーバー上の別のページにフォームデータを送信し、セッション情報と投稿をpaypalに追加することをお勧めします。また、なぜテーブルがフォームで使用されているのかよく分かりません。それは必要ではないようです。

ユーザー入力ページ

<form action="path/to/submit_page.php" method="post" target="_top"> <!-- I want it to verify first if the $_POST['custom'] is equal to the $_SESSION['id'] before it goes to the PayPal website.--> 
<input type="hidden" name="cmd" value="_s-xclick"> 
<input type="hidden" name="hosted_button_id" value="*********"> 
<table> 
    <tr> 
     <td> 
      <input type="hidden" name="on0" value="Items">Items 
     </td> 
    </tr> 
    <tr> 
     <td> 
      <select name="os0"> 
       <option value="Item1">Item1 $1.00 USD</option> 
       <option value="Item2">Item2 $2.00 USD</option> 
      </select> 
     </td> 
    </tr> 
</table> 
<input type="hidden" name="currency_code" value="USD"> 
<input type="submit" name="submit" value="Buy now" /> 
</form> 

submit_page.php

<?php 

session_start(); 

$url = 'https://www.sandbox.paypal.com/cgi-bin/webscr'; 

// Specify everything you need to send here 
$data = array('os0' => $_POST['os0'], 'currency_code' => $_POST['currency_code'], 'custom' => $_SESSION['id'], ...); 

$options = array(
    'http' => array(
     'header' => "Content-type: application/x-www-form-urlencoded\r\n", 
     'method' => 'POST', 
     'content' => http_build_query($data) 
    ) 
); 
$context = stream_context_create($options); 
$result = file_get_contents($url, false, $context); 
if ($result === FALSE) { /* Handle error */ } 

// Send user to success page 
+0

file_get_contents(https://www.sandbox.paypal.com/cgi-bin/webscr):ストリームのオープンに失敗しました:HTTP要求に失敗しました! HTTP/1.0 400不正リクエスト – Owsap

関連する問題