How to post data in PHP using file_get_contents?How to HTTP POST a XML File using PHP without cURL?How to send POST data through PHPSending post data along with file_get_contents()Can file_get_contents be used to post?How to fix 'file_get_contents(): Content-type not specified…'?PHP file_get_contents() and setting request headersAdding subscribers to a list using Mailchimp's API v3Need response body of HTTP 500 with file_get_contents (PHP)Using proxy with file_get_contentsSend AJAX-like post request using PHP onlyHow can I prevent SQL injection in PHP?JavaScript post request like a form submitPHP: Delete an element from an arrayPUT vs. POST in RESTHow do I get PHP errors to display?How Do You Parse and Process HTML/XML in PHP?Reference — What does this symbol mean in PHP?How does PHP 'foreach' actually work?Why shouldn't I use mysql_* functions in PHP?How are parameters sent in an HTTP POST request?

Domain expired, GoDaddy holds it and is asking more money

Is it legal to have the "// (c) 2019 John Smith" header in all files when there are hundreds of contributors?

Patience, young "Padovan"

What to wear for invited talk in Canada

What is the offset in a seaplane's hull?

Information to fellow intern about hiring?

Is this food a bread or a loaf?

Are objects structures and/or vice versa?

How to deal with fear of taking dependencies

Pristine Bit Checking

What does 'script /dev/null' do?

What is the command to reset a PC without deleting any files

Is every set a filtered colimit of finite sets?

Is there a way to make member function NOT callable from constructor?

How can I add custom success page

How did the USSR manage to innovate in an environment characterized by government censorship and high bureaucracy?

Was there ever an axiom rendered a theorem?

What do the Banks children have against barley water?

Are white and non-white police officers equally likely to kill black suspects?

"My colleague's body is amazing"

What do you call something that goes against the spirit of the law, but is legal when interpreting the law to the letter?

Shall I use personal or official e-mail account when registering to external websites for work purpose?

Is "plugging out" electronic devices an American expression?

What happens when a metallic dragon and a chromatic dragon mate?



How to post data in PHP using file_get_contents?


How to HTTP POST a XML File using PHP without cURL?How to send POST data through PHPSending post data along with file_get_contents()Can file_get_contents be used to post?How to fix 'file_get_contents(): Content-type not specified…'?PHP file_get_contents() and setting request headersAdding subscribers to a list using Mailchimp's API v3Need response body of HTTP 500 with file_get_contents (PHP)Using proxy with file_get_contentsSend AJAX-like post request using PHP onlyHow can I prevent SQL injection in PHP?JavaScript post request like a form submitPHP: Delete an element from an arrayPUT vs. POST in RESTHow do I get PHP errors to display?How Do You Parse and Process HTML/XML in PHP?Reference — What does this symbol mean in PHP?How does PHP 'foreach' actually work?Why shouldn't I use mysql_* functions in PHP?How are parameters sent in an HTTP POST request?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








270















I'm using PHP's function file_get_contents() to fetch contents of a URL and then I process headers through the variable $http_response_header.



Now the problem is that some of the URLs need some data to be posted to the URL (for example, login pages).



How do I do that?



I realize using stream_context I may be able to do that but I am not entirely clear.



Thanks.










share|improve this question
























  • php.net/manual/en/function.stream-context-create.php#89080

    – Ben
    Jul 28 '14 at 20:56






  • 5





    This should be upvoted infinitely. There is no reason to use Curl/Guzzle or any other fancy library if you have raw PHP functionality that do the job.

    – Omar Abid
    Mar 26 '15 at 21:03

















270















I'm using PHP's function file_get_contents() to fetch contents of a URL and then I process headers through the variable $http_response_header.



Now the problem is that some of the URLs need some data to be posted to the URL (for example, login pages).



How do I do that?



I realize using stream_context I may be able to do that but I am not entirely clear.



Thanks.










share|improve this question
























  • php.net/manual/en/function.stream-context-create.php#89080

    – Ben
    Jul 28 '14 at 20:56






  • 5





    This should be upvoted infinitely. There is no reason to use Curl/Guzzle or any other fancy library if you have raw PHP functionality that do the job.

    – Omar Abid
    Mar 26 '15 at 21:03













270












270








270


139






I'm using PHP's function file_get_contents() to fetch contents of a URL and then I process headers through the variable $http_response_header.



Now the problem is that some of the URLs need some data to be posted to the URL (for example, login pages).



How do I do that?



I realize using stream_context I may be able to do that but I am not entirely clear.



Thanks.










share|improve this question
















I'm using PHP's function file_get_contents() to fetch contents of a URL and then I process headers through the variable $http_response_header.



Now the problem is that some of the URLs need some data to be posted to the URL (for example, login pages).



How do I do that?



I realize using stream_context I may be able to do that but I am not entirely clear.



Thanks.







php http http-post file-get-contents






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 3 '12 at 10:46









dnlcrl

3,01732538




3,01732538










asked Mar 15 '10 at 5:27









Paras ChopraParas Chopra

1,85441617




1,85441617












  • php.net/manual/en/function.stream-context-create.php#89080

    – Ben
    Jul 28 '14 at 20:56






  • 5





    This should be upvoted infinitely. There is no reason to use Curl/Guzzle or any other fancy library if you have raw PHP functionality that do the job.

    – Omar Abid
    Mar 26 '15 at 21:03

















  • php.net/manual/en/function.stream-context-create.php#89080

    – Ben
    Jul 28 '14 at 20:56






  • 5





    This should be upvoted infinitely. There is no reason to use Curl/Guzzle or any other fancy library if you have raw PHP functionality that do the job.

    – Omar Abid
    Mar 26 '15 at 21:03
















php.net/manual/en/function.stream-context-create.php#89080

– Ben
Jul 28 '14 at 20:56





php.net/manual/en/function.stream-context-create.php#89080

– Ben
Jul 28 '14 at 20:56




5




5





This should be upvoted infinitely. There is no reason to use Curl/Guzzle or any other fancy library if you have raw PHP functionality that do the job.

– Omar Abid
Mar 26 '15 at 21:03





This should be upvoted infinitely. There is no reason to use Curl/Guzzle or any other fancy library if you have raw PHP functionality that do the job.

– Omar Abid
Mar 26 '15 at 21:03












3 Answers
3






active

oldest

votes


















541














Sending an HTTP POST request using file_get_contents is not that hard, actually : as you guessed, you have to use the $context parameter.





There's an example given in the PHP manual, at this page : HTTP context options (quoting) :



$postdata = http_build_query(
array(
'var1' => 'some content',
'var2' => 'doh'
)
);

$opts = array('http' =>
array(
'method' => 'POST',
'header' => 'Content-Type: application/x-www-form-urlencoded',
'content' => $postdata
)
);

$context = stream_context_create($opts);

$result = file_get_contents('http://example.com/submit.php', false, $context);


Basically, you have to create a stream, with the right options (there is a full list on that page), and use it as the third parameter to file_get_contents -- nothing more ;-)





As a sidenote : generally speaking, to send HTTP POST requests, we tend to use curl, which provides a lot of options an all -- but streams are one of the nice things of PHP that nobody knows about... too bad...






share|improve this answer




















  • 1





    Thanks. I am guessing I can insert the contents from $_POST into $postdata if I need to pass same POST params to the requested page?

    – Paras Chopra
    Mar 15 '10 at 6:49






  • 6





    I suppose you can do something like that ; but content must not be a PHP array : it has to be a querystring (i.e. it must has this format : param1=value1&param2=value2&param3=value3 ) ;; which means you'll probably have to use http_build_query($_POST)

    – Pascal MARTIN
    Mar 15 '10 at 6:52






  • 2





    Wonderful! I was looking for a way to pass POST data to another page which is achievable by doing $postdata = http_build_query($_POST).

    – Liam Newmarch
    Nov 30 '11 at 12:20






  • 1





    intresting enough this does not work for me at all i been tryiung it for a few hours and all my requets get turned into get querys

    – WojonsTech
    Oct 2 '12 at 7:01











  • What if the parameters value are not strings but arrays or hashes etc ?

    – oldergod
    Jun 10 '13 at 6:17


















18














An alternative, you can also use fopen



$params = array('http' => array(
'method' => 'POST',
'content' => 'toto=1&tata=2'
));

$ctx = stream_context_create($params);
$fp = @fopen($sUrl, 'rb', false, $ctx);
if (!$fp)

throw new Exception("Problem with $sUrl, $php_errormsg");


$response = @stream_get_contents($fp);
if ($response === false)

throw new Exception("Problem reading data from $sUrl, $php_errormsg");






share|improve this answer























  • For some reason, this worked for me, but the PHP official example did not. +1 for the toto=1&tata=2 as well. I didn't use the fopen, however.

    – Michael Yaworski
    Jul 17 '15 at 19:09







  • 4





    @Ġiĺàɗ We don't call people 'noob' here. This is a friendly warning against such.

    – Daedalus
    Jan 26 '16 at 10:35


















0














$sUrl = 'http://www.linktopage.com/login/';
$params = array('http' => array(
'method' => 'POST',
'content' => 'username=admin195&password=d123456789'
));

$ctx = stream_context_create($params);
$fp = @fopen($sUrl, 'rb', false, $ctx);
if(!$fp)
throw new Exception("Problem with $sUrl, $php_errormsg");


$response = @stream_get_contents($fp);
if($response === false)
throw new Exception("Problem reading data from $sUrl, $php_errormsg");






share|improve this answer




















  • 1





    Please, try to provide an elaborated answer instead of simply copying/pasting code.

    – Felipe Leão
    Apr 6 '18 at 18:18











  • Also this is unnecessarily complicated. You can use file_get_contents instead of fopen + stream_get_contents. And you are not even closing the "file". See the accepted answer by @PascalMARTIN.

    – Martin Prikryl
    Sep 21 '18 at 11:20










protected by Community Oct 25 '13 at 12:52



Thank you for your interest in this question.
Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).



Would you like to answer one of these unanswered questions instead?














3 Answers
3






active

oldest

votes








3 Answers
3






active

oldest

votes









active

oldest

votes






active

oldest

votes









541














Sending an HTTP POST request using file_get_contents is not that hard, actually : as you guessed, you have to use the $context parameter.





There's an example given in the PHP manual, at this page : HTTP context options (quoting) :



$postdata = http_build_query(
array(
'var1' => 'some content',
'var2' => 'doh'
)
);

$opts = array('http' =>
array(
'method' => 'POST',
'header' => 'Content-Type: application/x-www-form-urlencoded',
'content' => $postdata
)
);

$context = stream_context_create($opts);

$result = file_get_contents('http://example.com/submit.php', false, $context);


Basically, you have to create a stream, with the right options (there is a full list on that page), and use it as the third parameter to file_get_contents -- nothing more ;-)





As a sidenote : generally speaking, to send HTTP POST requests, we tend to use curl, which provides a lot of options an all -- but streams are one of the nice things of PHP that nobody knows about... too bad...






share|improve this answer




















  • 1





    Thanks. I am guessing I can insert the contents from $_POST into $postdata if I need to pass same POST params to the requested page?

    – Paras Chopra
    Mar 15 '10 at 6:49






  • 6





    I suppose you can do something like that ; but content must not be a PHP array : it has to be a querystring (i.e. it must has this format : param1=value1&param2=value2&param3=value3 ) ;; which means you'll probably have to use http_build_query($_POST)

    – Pascal MARTIN
    Mar 15 '10 at 6:52






  • 2





    Wonderful! I was looking for a way to pass POST data to another page which is achievable by doing $postdata = http_build_query($_POST).

    – Liam Newmarch
    Nov 30 '11 at 12:20






  • 1





    intresting enough this does not work for me at all i been tryiung it for a few hours and all my requets get turned into get querys

    – WojonsTech
    Oct 2 '12 at 7:01











  • What if the parameters value are not strings but arrays or hashes etc ?

    – oldergod
    Jun 10 '13 at 6:17















541














Sending an HTTP POST request using file_get_contents is not that hard, actually : as you guessed, you have to use the $context parameter.





There's an example given in the PHP manual, at this page : HTTP context options (quoting) :



$postdata = http_build_query(
array(
'var1' => 'some content',
'var2' => 'doh'
)
);

$opts = array('http' =>
array(
'method' => 'POST',
'header' => 'Content-Type: application/x-www-form-urlencoded',
'content' => $postdata
)
);

$context = stream_context_create($opts);

$result = file_get_contents('http://example.com/submit.php', false, $context);


Basically, you have to create a stream, with the right options (there is a full list on that page), and use it as the third parameter to file_get_contents -- nothing more ;-)





As a sidenote : generally speaking, to send HTTP POST requests, we tend to use curl, which provides a lot of options an all -- but streams are one of the nice things of PHP that nobody knows about... too bad...






share|improve this answer




















  • 1





    Thanks. I am guessing I can insert the contents from $_POST into $postdata if I need to pass same POST params to the requested page?

    – Paras Chopra
    Mar 15 '10 at 6:49






  • 6





    I suppose you can do something like that ; but content must not be a PHP array : it has to be a querystring (i.e. it must has this format : param1=value1&param2=value2&param3=value3 ) ;; which means you'll probably have to use http_build_query($_POST)

    – Pascal MARTIN
    Mar 15 '10 at 6:52






  • 2





    Wonderful! I was looking for a way to pass POST data to another page which is achievable by doing $postdata = http_build_query($_POST).

    – Liam Newmarch
    Nov 30 '11 at 12:20






  • 1





    intresting enough this does not work for me at all i been tryiung it for a few hours and all my requets get turned into get querys

    – WojonsTech
    Oct 2 '12 at 7:01











  • What if the parameters value are not strings but arrays or hashes etc ?

    – oldergod
    Jun 10 '13 at 6:17













541












541








541







Sending an HTTP POST request using file_get_contents is not that hard, actually : as you guessed, you have to use the $context parameter.





There's an example given in the PHP manual, at this page : HTTP context options (quoting) :



$postdata = http_build_query(
array(
'var1' => 'some content',
'var2' => 'doh'
)
);

$opts = array('http' =>
array(
'method' => 'POST',
'header' => 'Content-Type: application/x-www-form-urlencoded',
'content' => $postdata
)
);

$context = stream_context_create($opts);

$result = file_get_contents('http://example.com/submit.php', false, $context);


Basically, you have to create a stream, with the right options (there is a full list on that page), and use it as the third parameter to file_get_contents -- nothing more ;-)





As a sidenote : generally speaking, to send HTTP POST requests, we tend to use curl, which provides a lot of options an all -- but streams are one of the nice things of PHP that nobody knows about... too bad...






share|improve this answer















Sending an HTTP POST request using file_get_contents is not that hard, actually : as you guessed, you have to use the $context parameter.





There's an example given in the PHP manual, at this page : HTTP context options (quoting) :



$postdata = http_build_query(
array(
'var1' => 'some content',
'var2' => 'doh'
)
);

$opts = array('http' =>
array(
'method' => 'POST',
'header' => 'Content-Type: application/x-www-form-urlencoded',
'content' => $postdata
)
);

$context = stream_context_create($opts);

$result = file_get_contents('http://example.com/submit.php', false, $context);


Basically, you have to create a stream, with the right options (there is a full list on that page), and use it as the third parameter to file_get_contents -- nothing more ;-)





As a sidenote : generally speaking, to send HTTP POST requests, we tend to use curl, which provides a lot of options an all -- but streams are one of the nice things of PHP that nobody knows about... too bad...







share|improve this answer














share|improve this answer



share|improve this answer








edited Mar 22 at 1:39









Volomike

14k1882156




14k1882156










answered Mar 15 '10 at 5:44









Pascal MARTINPascal MARTIN

341k59589616




341k59589616







  • 1





    Thanks. I am guessing I can insert the contents from $_POST into $postdata if I need to pass same POST params to the requested page?

    – Paras Chopra
    Mar 15 '10 at 6:49






  • 6





    I suppose you can do something like that ; but content must not be a PHP array : it has to be a querystring (i.e. it must has this format : param1=value1&param2=value2&param3=value3 ) ;; which means you'll probably have to use http_build_query($_POST)

    – Pascal MARTIN
    Mar 15 '10 at 6:52






  • 2





    Wonderful! I was looking for a way to pass POST data to another page which is achievable by doing $postdata = http_build_query($_POST).

    – Liam Newmarch
    Nov 30 '11 at 12:20






  • 1





    intresting enough this does not work for me at all i been tryiung it for a few hours and all my requets get turned into get querys

    – WojonsTech
    Oct 2 '12 at 7:01











  • What if the parameters value are not strings but arrays or hashes etc ?

    – oldergod
    Jun 10 '13 at 6:17












  • 1





    Thanks. I am guessing I can insert the contents from $_POST into $postdata if I need to pass same POST params to the requested page?

    – Paras Chopra
    Mar 15 '10 at 6:49






  • 6





    I suppose you can do something like that ; but content must not be a PHP array : it has to be a querystring (i.e. it must has this format : param1=value1&param2=value2&param3=value3 ) ;; which means you'll probably have to use http_build_query($_POST)

    – Pascal MARTIN
    Mar 15 '10 at 6:52






  • 2





    Wonderful! I was looking for a way to pass POST data to another page which is achievable by doing $postdata = http_build_query($_POST).

    – Liam Newmarch
    Nov 30 '11 at 12:20






  • 1





    intresting enough this does not work for me at all i been tryiung it for a few hours and all my requets get turned into get querys

    – WojonsTech
    Oct 2 '12 at 7:01











  • What if the parameters value are not strings but arrays or hashes etc ?

    – oldergod
    Jun 10 '13 at 6:17







1




1





Thanks. I am guessing I can insert the contents from $_POST into $postdata if I need to pass same POST params to the requested page?

– Paras Chopra
Mar 15 '10 at 6:49





Thanks. I am guessing I can insert the contents from $_POST into $postdata if I need to pass same POST params to the requested page?

– Paras Chopra
Mar 15 '10 at 6:49




6




6





I suppose you can do something like that ; but content must not be a PHP array : it has to be a querystring (i.e. it must has this format : param1=value1&param2=value2&param3=value3 ) ;; which means you'll probably have to use http_build_query($_POST)

– Pascal MARTIN
Mar 15 '10 at 6:52





I suppose you can do something like that ; but content must not be a PHP array : it has to be a querystring (i.e. it must has this format : param1=value1&param2=value2&param3=value3 ) ;; which means you'll probably have to use http_build_query($_POST)

– Pascal MARTIN
Mar 15 '10 at 6:52




2




2





Wonderful! I was looking for a way to pass POST data to another page which is achievable by doing $postdata = http_build_query($_POST).

– Liam Newmarch
Nov 30 '11 at 12:20





Wonderful! I was looking for a way to pass POST data to another page which is achievable by doing $postdata = http_build_query($_POST).

– Liam Newmarch
Nov 30 '11 at 12:20




1




1





intresting enough this does not work for me at all i been tryiung it for a few hours and all my requets get turned into get querys

– WojonsTech
Oct 2 '12 at 7:01





intresting enough this does not work for me at all i been tryiung it for a few hours and all my requets get turned into get querys

– WojonsTech
Oct 2 '12 at 7:01













What if the parameters value are not strings but arrays or hashes etc ?

– oldergod
Jun 10 '13 at 6:17





What if the parameters value are not strings but arrays or hashes etc ?

– oldergod
Jun 10 '13 at 6:17













18














An alternative, you can also use fopen



$params = array('http' => array(
'method' => 'POST',
'content' => 'toto=1&tata=2'
));

$ctx = stream_context_create($params);
$fp = @fopen($sUrl, 'rb', false, $ctx);
if (!$fp)

throw new Exception("Problem with $sUrl, $php_errormsg");


$response = @stream_get_contents($fp);
if ($response === false)

throw new Exception("Problem reading data from $sUrl, $php_errormsg");






share|improve this answer























  • For some reason, this worked for me, but the PHP official example did not. +1 for the toto=1&tata=2 as well. I didn't use the fopen, however.

    – Michael Yaworski
    Jul 17 '15 at 19:09







  • 4





    @Ġiĺàɗ We don't call people 'noob' here. This is a friendly warning against such.

    – Daedalus
    Jan 26 '16 at 10:35















18














An alternative, you can also use fopen



$params = array('http' => array(
'method' => 'POST',
'content' => 'toto=1&tata=2'
));

$ctx = stream_context_create($params);
$fp = @fopen($sUrl, 'rb', false, $ctx);
if (!$fp)

throw new Exception("Problem with $sUrl, $php_errormsg");


$response = @stream_get_contents($fp);
if ($response === false)

throw new Exception("Problem reading data from $sUrl, $php_errormsg");






share|improve this answer























  • For some reason, this worked for me, but the PHP official example did not. +1 for the toto=1&tata=2 as well. I didn't use the fopen, however.

    – Michael Yaworski
    Jul 17 '15 at 19:09







  • 4





    @Ġiĺàɗ We don't call people 'noob' here. This is a friendly warning against such.

    – Daedalus
    Jan 26 '16 at 10:35













18












18








18







An alternative, you can also use fopen



$params = array('http' => array(
'method' => 'POST',
'content' => 'toto=1&tata=2'
));

$ctx = stream_context_create($params);
$fp = @fopen($sUrl, 'rb', false, $ctx);
if (!$fp)

throw new Exception("Problem with $sUrl, $php_errormsg");


$response = @stream_get_contents($fp);
if ($response === false)

throw new Exception("Problem reading data from $sUrl, $php_errormsg");






share|improve this answer













An alternative, you can also use fopen



$params = array('http' => array(
'method' => 'POST',
'content' => 'toto=1&tata=2'
));

$ctx = stream_context_create($params);
$fp = @fopen($sUrl, 'rb', false, $ctx);
if (!$fp)

throw new Exception("Problem with $sUrl, $php_errormsg");


$response = @stream_get_contents($fp);
if ($response === false)

throw new Exception("Problem reading data from $sUrl, $php_errormsg");







share|improve this answer












share|improve this answer



share|improve this answer










answered Jun 9 '13 at 19:29









MacbricMacbric

38439




38439












  • For some reason, this worked for me, but the PHP official example did not. +1 for the toto=1&tata=2 as well. I didn't use the fopen, however.

    – Michael Yaworski
    Jul 17 '15 at 19:09







  • 4





    @Ġiĺàɗ We don't call people 'noob' here. This is a friendly warning against such.

    – Daedalus
    Jan 26 '16 at 10:35

















  • For some reason, this worked for me, but the PHP official example did not. +1 for the toto=1&tata=2 as well. I didn't use the fopen, however.

    – Michael Yaworski
    Jul 17 '15 at 19:09







  • 4





    @Ġiĺàɗ We don't call people 'noob' here. This is a friendly warning against such.

    – Daedalus
    Jan 26 '16 at 10:35
















For some reason, this worked for me, but the PHP official example did not. +1 for the toto=1&tata=2 as well. I didn't use the fopen, however.

– Michael Yaworski
Jul 17 '15 at 19:09






For some reason, this worked for me, but the PHP official example did not. +1 for the toto=1&tata=2 as well. I didn't use the fopen, however.

– Michael Yaworski
Jul 17 '15 at 19:09





4




4





@Ġiĺàɗ We don't call people 'noob' here. This is a friendly warning against such.

– Daedalus
Jan 26 '16 at 10:35





@Ġiĺàɗ We don't call people 'noob' here. This is a friendly warning against such.

– Daedalus
Jan 26 '16 at 10:35











0














$sUrl = 'http://www.linktopage.com/login/';
$params = array('http' => array(
'method' => 'POST',
'content' => 'username=admin195&password=d123456789'
));

$ctx = stream_context_create($params);
$fp = @fopen($sUrl, 'rb', false, $ctx);
if(!$fp)
throw new Exception("Problem with $sUrl, $php_errormsg");


$response = @stream_get_contents($fp);
if($response === false)
throw new Exception("Problem reading data from $sUrl, $php_errormsg");






share|improve this answer




















  • 1





    Please, try to provide an elaborated answer instead of simply copying/pasting code.

    – Felipe Leão
    Apr 6 '18 at 18:18











  • Also this is unnecessarily complicated. You can use file_get_contents instead of fopen + stream_get_contents. And you are not even closing the "file". See the accepted answer by @PascalMARTIN.

    – Martin Prikryl
    Sep 21 '18 at 11:20
















0














$sUrl = 'http://www.linktopage.com/login/';
$params = array('http' => array(
'method' => 'POST',
'content' => 'username=admin195&password=d123456789'
));

$ctx = stream_context_create($params);
$fp = @fopen($sUrl, 'rb', false, $ctx);
if(!$fp)
throw new Exception("Problem with $sUrl, $php_errormsg");


$response = @stream_get_contents($fp);
if($response === false)
throw new Exception("Problem reading data from $sUrl, $php_errormsg");






share|improve this answer




















  • 1





    Please, try to provide an elaborated answer instead of simply copying/pasting code.

    – Felipe Leão
    Apr 6 '18 at 18:18











  • Also this is unnecessarily complicated. You can use file_get_contents instead of fopen + stream_get_contents. And you are not even closing the "file". See the accepted answer by @PascalMARTIN.

    – Martin Prikryl
    Sep 21 '18 at 11:20














0












0








0







$sUrl = 'http://www.linktopage.com/login/';
$params = array('http' => array(
'method' => 'POST',
'content' => 'username=admin195&password=d123456789'
));

$ctx = stream_context_create($params);
$fp = @fopen($sUrl, 'rb', false, $ctx);
if(!$fp)
throw new Exception("Problem with $sUrl, $php_errormsg");


$response = @stream_get_contents($fp);
if($response === false)
throw new Exception("Problem reading data from $sUrl, $php_errormsg");






share|improve this answer















$sUrl = 'http://www.linktopage.com/login/';
$params = array('http' => array(
'method' => 'POST',
'content' => 'username=admin195&password=d123456789'
));

$ctx = stream_context_create($params);
$fp = @fopen($sUrl, 'rb', false, $ctx);
if(!$fp)
throw new Exception("Problem with $sUrl, $php_errormsg");


$response = @stream_get_contents($fp);
if($response === false)
throw new Exception("Problem reading data from $sUrl, $php_errormsg");







share|improve this answer














share|improve this answer



share|improve this answer








edited Sep 21 '18 at 10:20









step

6212929




6212929










answered Apr 12 '15 at 17:47









user2525449user2525449

141119




141119







  • 1





    Please, try to provide an elaborated answer instead of simply copying/pasting code.

    – Felipe Leão
    Apr 6 '18 at 18:18











  • Also this is unnecessarily complicated. You can use file_get_contents instead of fopen + stream_get_contents. And you are not even closing the "file". See the accepted answer by @PascalMARTIN.

    – Martin Prikryl
    Sep 21 '18 at 11:20













  • 1





    Please, try to provide an elaborated answer instead of simply copying/pasting code.

    – Felipe Leão
    Apr 6 '18 at 18:18











  • Also this is unnecessarily complicated. You can use file_get_contents instead of fopen + stream_get_contents. And you are not even closing the "file". See the accepted answer by @PascalMARTIN.

    – Martin Prikryl
    Sep 21 '18 at 11:20








1




1





Please, try to provide an elaborated answer instead of simply copying/pasting code.

– Felipe Leão
Apr 6 '18 at 18:18





Please, try to provide an elaborated answer instead of simply copying/pasting code.

– Felipe Leão
Apr 6 '18 at 18:18













Also this is unnecessarily complicated. You can use file_get_contents instead of fopen + stream_get_contents. And you are not even closing the "file". See the accepted answer by @PascalMARTIN.

– Martin Prikryl
Sep 21 '18 at 11:20






Also this is unnecessarily complicated. You can use file_get_contents instead of fopen + stream_get_contents. And you are not even closing the "file". See the accepted answer by @PascalMARTIN.

– Martin Prikryl
Sep 21 '18 at 11:20






protected by Community Oct 25 '13 at 12:52



Thank you for your interest in this question.
Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).



Would you like to answer one of these unanswered questions instead?



Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현