-2

I want to send some data to another server but I don't want user to view the data. I tried submitting form but others still manage to see the data even it is hidden.
PS: The server only receives $_POST.

curveball
  • 4,320
  • 15
  • 39
  • 49
Jee Hong
  • 47
  • 1
  • 8

2 Answers2

1

You use curl for this purpose.

An example:

<?PHP
function POST($url,$data,$headers,$type)
{
    $ch = curl_init ($url);
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
    curl_setopt($ch, CURLOPT_VERBOSE, true);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
    curl_setopt ($ch, CURLOPT_POST, 1);

    if($type === 1)
    {
        curl_setopt($ch,CURLOPT_POSTFIELDS, http_build_query($data));
    }
    else
    {
        curl_setopt($ch,CURLOPT_POSTFIELDS, $data);
    }

    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    curl_setopt($ch, CURLINFO_HEADER_OUT, true);
    $output = curl_exec ($ch);
    $posturl = curl_getinfo($ch,CURLINFO_EFFECTIVE_URL);
    $httpCode = curl_getinfo($ch,CURLINFO_HTTP_CODE);
    $cURLinfo = curl_getinfo($ch);
    curl_close($ch);
    return array(
        "output" => $output,
        "posturl" => $posturl,
        "httpcode" => $httpCode,
        "diagnostics" => $cURLinfo
    );
}
?>

But most likely, this is a duplicate of How do I send a POST request with PHP?

maio290
  • 6,440
  • 1
  • 21
  • 38
-1

use forge.js to encrypt the data in base64 e.g.

jQuery.post('yourfile.php', 
              {uname: forge.util.encode64(jQuery('#uname').val()) , 
              upass: forge.util.encode64(jQuery('#upass').val() )
              },function(data) 
                {
                    console.log(data);
                 });

and then in PHP you can use

$user =  base64_decode($_POST['uname']);
$passw =  base64_decode($_POST['upass']);

to retrieve the data.

Satya
  • 8,693
  • 5
  • 34
  • 55
  • 1
    OP, did ask for via PHP –  Sep 24 '18 at 03:53
  • I believe what he meant was while submitting data via HTML the data needs to be encrypted, and proposed a solution based on this. If OP re-confirms he is asking to do it via PHP, I will delete the post happily – Satya Sep 24 '18 at 04:24
  • "but I don't want user to view the data" - and you use Javascript? base64 is not secure anyway. – maio290 Sep 24 '18 at 08:45