You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

DIBS支付前执行MD5操作及PHP触发MD5计算函数求助

How to Trigger MD5 Calculation for DIBS HTML Payment Form (PHP Newbie Guide)

Hey there! As someone who’s worked through DIBS payment integrations before, let’s break this down simply so you can get that MD5 calculation working smoothly before your payment form submits. The critical thing here is to compute the MD5 hash on your server first (never expose your key1 and key2 in frontend code—they’re secret!) and pass it to your HTML form as a hidden field.

Step 1: Compute the MD5 Hash in PHP

First, let’s make sure your PHP code is set up with all the right values. Replace the placeholders with your actual DIBS credentials and order details:

// Replace these with your real DIBS info and order data
$yourMerchantID = 'YOUR_MERCHANT_ID';
$yourOrderID = 'UNIQUE_ORDER_NUMBER'; // Generate this dynamically for each order
$yourCurrency = 'SEK'; // Use your preferred currency code (e.g., EUR, USD)
$yourAmount = '1000'; // Amount in the smallest unit (1000 = 10.00 SEK)
$key1 = 'YOUR_DIBS_KEY1';
$key2 = 'YOUR_DIBS_KEY2';

// Build the parameter string exactly as DIBS requires
$parameter_string = '';
$parameter_string .= 'merchant=' . $yourMerchantID;
$parameter_string .= '&orderid=' . $yourOrderID;
$parameter_string .= '&currency=' . $yourCurrency;
$parameter_string .= '&amount=' . $yourAmount;

// Calculate the nested MD5 key per DIBS instructions
$md5key = md5($key2 . md5($key1 . $parameter_string));

Heads up: Don’t mix up the order of key1, key2, and the parameter string—DIBS’ validation depends on this exact nesting!

Step 2: Add the MD5 Hash to Your HTML Form

Now, insert the computed $md5key as a hidden input into your DIBS payment form. This way, when the form submits, the hash is sent along with all other payment data to DIBS:

<form id="payment-form" action="https://payment.archive.dibspayment.com/payment/dbw/" method="POST">
    <!-- Hidden fields with your order and merchant data -->
    <input type="hidden" name="merchant" value="<?php echo $yourMerchantID; ?>">
    <input type="hidden" name="orderid" value="<?php echo $yourOrderID; ?>">
    <input type="hidden" name="currency" value="<?php echo $yourCurrency; ?>">
    <input type="hidden" name="amount" value="<?php echo $yourAmount; ?>">
    
    <!-- The pre-computed MD5 key (critical for DIBS validation) -->
    <input type="hidden" name="md5key" value="<?php echo $md5key; ?>">
    
    <!-- Your submit button -->
    <button type="submit">Pay Now</button>
</form>

Quick Tips for PHP Newbies

  • Keep keys secret: Never put key1 or key2 in JavaScript or frontend code—anyone could steal them. Always do the MD5 calculation server-side.
  • Dynamic values: For real orders, generate $yourOrderID, $yourAmount, etc., from your database or shopping cart (don’t hardcode them like in the example).
  • Test first: Use DIBS’ test environment to double-check the hash works before going live—this saves you headaches later!

That’s all there is to it! When your user clicks "Pay Now", the form sends all the required data (including the pre-computed MD5 key) to DIBS, which will validate the hash to make sure the payment request hasn’t been tampered with.

内容的提问来源于stack exchange,提问作者Kuanl

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.20 11:30:36