0

I have a web page A created by a PHP script which would need to use a service only available on another page B – and for various reasons, A and B can't be merged. In this particular instance, page A is a non-WordPress page and page B is WordPress-generated. And the service in question is sending emails in a specific format which is supplied by a WP plugin.

My idea is to use page A to generate the email content and then send that content to page B which then, aided by the plugin, sends the email in the appropriate format and transfers control back to page A. This would be perfectly doable – but what I would like in addition is for page B never to be displayed. The visitor should have the impression that they are dealing only with page A all the time. Can that be done and if so, how?

I do not intend this to be a WordPress question (although maybe it is), rather more generally about using another page's script in passing without displaying that other page.

2 Answers 2

1

If you do have source access, it would be most reliable to use the addon directly... But if you cannot, the second easiest would be to use curl to mimic the form post on page B. This would happen server side so the user wouldn't see it happening.

To figure out what you need to send in your POST request, open your browser's developer tools and watch the network tab when you send the form manually, take the URL, and all the post data. Then you'll be able to mimic it.

3
  • Never heard of curl before, but yes that seems to be exactly what I'm looking for. Thanks a lot. This article helped me to grasp how to POST data using curl. davidwalsh.name/curl-post
    – danbae
    Nov 9, 2017 at 20:10
  • A bit annoying that the output from page B is shown by default. Better if it were stored in a variable that the coder could decide themselves what to do with. I solved that by putting the php-curl code inside an invisible div.
    – danbae
    Nov 9, 2017 at 22:14
  • I take that back, just found out about CURLOPT_RETURNTRANSFER stackoverflow.com/questions/18203411/…
    – danbae
    Nov 9, 2017 at 23:22
1

You may proxy https://SITEA.com/siteB/whatever to http://SITEB.com/whatever - or the other way around... I didn't fully understand the process :P

In case you just want the siteB service call, you may also send the requests via curl or a HTTP library of your choice - which might be better as you will have to get a nonce first and stuff like that.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.