Submit form on one server, process it and then post results to another domain

后端 未结 2 1953
你的背包
你的背包 2021-01-15 20:25

I have a form on one page with the action set to /process.php

Within the process.php I have the validation of the form and also it writes to a database on the server

2条回答
  •  既然无缘
    2021-01-15 20:55

    Example using curl:

    $name = 'Test';
    $email = 'test@gmail.com';
    
    $ch = curl_init(); // initialize curl handle
    $url = "http://domain2.com/process.php"; 
    curl_setopt($ch, CURLOPT_URL,$url);
    curl_setopt($ch, CURLOPT_FAILONERROR, 1);
    curl_setopt($ch, CURLOPT_TIMEOUT, 10); // times out after 10s
    curl_setopt($ch, CURLOPT_POST, 1); // set POST method
    curl_setopt($ch, CURLOPT_POSTFIELDS, "text=$name&name=$email"); // post fields
    $data = curl_exec($ch); // run the whole process
    curl_close($ch);
    

    Example without curl: http://wezfurlong.org/blog/2006/nov/http-post-from-php-without-curl/

提交回复
热议问题