Can some please tell me the correct, secure way to POST to a file on another domain? I have two domains. Actually, in this particular instance, I'm working with two subdomains that are hosted on the same server. - www.mysite.com - support.mysite.com I have a function on support.mysite.com that needs to POST to a file on www.mysite.com. The file being POSTed to is not in the root. The file is here: www.mysite.com/folder/file.php. Here's what I have so far but it does not work: $fp = fsockopen('127.0.0.1', 80); if ($fp !== false) { $vars = array( 'time' => $time, 'hash' => $hash, 'name' => $Name, 'email' => $email, 'password' => $rand_password, ); $content = http_build_query($vars); fwrite($fp, "POST /folder/file.php HTTP/1.1\r\n"); fwrite($fp, "Host: www.mysite.com\r\n"); fwrite($fp, "Content-Type: application/x-www-form-urlencoded\r\n"); fwrite($fp, "Content-Length: " . strlen($content) . "\r\n"); fwrite($fp, "Connection: close\r\n"); fwrite($fp, "\r\n"); fwrite($fp, $content); fclose($fp); } PHP: I think the problem is line 14 and 15. I tested the code (it worked) by relocating 'file.php' to the root of 'www.mysite.com' and editing line 14 as below: fwrite($fp, "POST /file.php HTTP/1.1\r\n"); PHP: ...but I need 'file.php' to be in a specific subdirectory (e.g., www.mysite.com/folder/file.php)
To be honest, I don't remember. This was something that I implemented a while back on another site. Now I'm trying to replicate what did on another site but this time 'file.php' is not in the root. I can't remember why I did not use cURL but there was a reason because I remember debating which one to use . It could have simply been the fact that I could not get it to work with cURL or that someone told me fsockopen is more efficient than cURL. What would the code look like in cURL?
It could be something like that <?php $vars = array( 'time' => $time, 'hash' => $hash, 'name' => $Name, 'email' => $email, 'password' => $rand_password, ); if( $curl = curl_init() ) { curl_setopt($curl, CURLOPT_URL, 'www.mysite.com/folder/file.php'); curl_setopt($curl, CURLOPT_RETURNTRANSFER,true); curl_setopt($curl, CURLOPT_POST, true); curl_setopt($curl, CURLOPT_POSTFIELDS, $vars); $result = curl_exec($curl); curl_close($curl); echo $result; } ?> PHP:
Thanks Sano000. What should the URL be if my server's file structure is such and I do not want to go over the Internet: C:/wamp/websites/www.mysite.com/folder/file.php C:/wamp/websites/support.mysite.com