Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML Form POST Cross Domain

I have a very simple HTML form that uses POST and its action calls a PHP script on my web server.

Here is the kicker... the html that contains the form isn't hosted on the same server and exists in a different domain. Without bogging down this question with explanation this has to be done for business reasons. They need to exist within these specific domains.

When I submit my form I access the PHP script correctly but then I try and pull out the POST data and it is gone. I'm thinking this is a security problem because I temporarily put the form on the same server as the PHP and it worked fine.

Is there a way that I can get this to work with the two separate domains? Thanks in advance.

Edit:

PHP Code (emailTemplate.php):

<?php
var_dump($_POST);
?>

HTML Form:

<form name="emailForm" id="emailForm" method="post" onsubmit="return beforeSubmit();" action="https://***.***.com/emailTemplate.php">
    <textarea rows="15" cols="75" id="myHtmlText" name="myHtmlText"></textarea>
    <input type="text" id="toAddr" name="toAddr" size="60"/>
    <input type="text" id="fromAddr" name="fromAddr" size="60"/>
    <input type="text" id="subjectLine" name="subjectLine" size="60"/>
    <input type="submit" name="Submit" value="Email Letter">
</form>
like image 332
jcmitch Avatar asked Dec 13 '11 23:12

jcmitch


People also ask

Can you post at a different domain?

You can cross-post content across several domains that you own, you can benefit from others republishing your own content, rent or purchase content on other sites, and safely use third-party distribution networks like Medium to spread the word.

Is it possible to post data from one domain to another domain if yes how can the same be done?

In short: YES, cross-domain POSTing is allowed.

Can you send an Ajax request to another domain?

Cross-origin resource sharing (or CORS) can be used to make AJAX requests to another domain.

What is the same origin policy in Web browsers?

The same-origin policy is a critical security mechanism that restricts how a document or script loaded by one origin can interact with a resource from another origin. It helps isolate potentially malicious documents, reducing possible attack vectors.


1 Answers

If you're only experiencing the issue in IE, their XSS filter may be to blame. This article provides details for disabling it.

To avoid this problem entirely, try posting your form to a PHP script on your server, and in that script, create a cURL session that posts the form to the other script. The XSS transaction occurs independently of the client's web browser, averting these browser-based security restrictions in the process.

like image 74
Aaron Avatar answered Oct 05 '22 05:10

Aaron