I need to do a POST request to an outside source with data from a file, so I tried to merge these 2 solutions I saw, but I can't seem to make them work, can you help me please?
// Submit those variables to the server
$post_data = array(
'test' => 'foobar',
'okay' => 'yes',
'number' => 2
);
// Send a request to example.com
$result = post_request('http://www.example.com/', $post_data);
if ($result['status'] == 'ok'){
// Print headers
echo $result['header'];
echo '<hr />';
// print the result of the whole request:
echo $result['content'];
}
else {
echo 'A error occured: ' . $result['error'];
}
And in array() I'm putting
$trimmed = file('somefile.txt', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
So in the end I get something like this
<?php
$post_data = array($trimmed = file('somefile.txt', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
$result = post_request('http://www.example.com/', $post_data);
if ($result['status'] == 'ok'){
echo $result['header'];
echo '<hr />';
echo $result['content'];
}
else {
echo 'A error occured: ' . $result['error'];
}
?>
EDIT: I'm sorry if I wasn't clear on what I need. Actually by chance I found someone with the same need as I here stackoverflow.com/questions/46582/response-redirect-with-post-instead-of-get although I wanted to do it with php.
Basically I was asked to make a quick form inside a website in which the user writes some credentials that are saved in a .txt and that data is used to log in via POST to an affiliate external website. This gives the user the confort of being able to login to the affiliate website from the first without having to click new links.