Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can you post data from PHP

Tags:

php

I need to cause a user's browser to post data using PHP to another site.

Example: You go to start.com/auto-login-hack (via GET)... then PHP sets the right headers etc. and causes the browser to, via POST, go to 3rdparty.com/login.php with login credentials.

I have done this is the past by having an HTML form and an onload script that submits the form to the destination.

I don't know enough about headers and etc. Is this possible? Can anyone link an example? My search skills just turned up how to use $_POST.

Thanks.

like image 209
Simon Avatar asked Aug 18 '26 07:08

Simon


2 Answers

Yes, you can submit POST requests from PHP.

One of your choices is to use curl as shown in this SO question.

However, you cannot do redirects.

like image 165
Peter Bailey Avatar answered Aug 20 '26 03:08

Peter Bailey


You cannot redirect to a POST; this is a limitation of HTTP. You'd have to use JavaScript to cause the browser to post a form.

like image 42
David Pfeffer Avatar answered Aug 20 '26 03:08

David Pfeffer



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!