Im sending post info by using php curl. its okay. no problem. however it sends server's IP. this is a problem for me.
jquery is sending post info with user's IP, however jQuery have cross domain problem. it is not sending post info to another domain. It only works for 开发者_StackOverflow社区same domain.
I wanna send post info (to another domain) + user ip (not server ip). Id like to learn your advices... Well, is there any other ways to make this job?
Thanks, Regards.
The only way to do this is to have a form on the web page that points to the specified resource, give it a POST
method, and submit it.
If you don't want the entire page to reload, use an iframe.
<iframe id="myiframe"></iframe>
<form action="http://some-other-site.com/page.php" method="post" target="myiframe">
....
You will, however, not be able to access the results the site outputs - again due to the cross domain / single origin policy.
If the "some-other-site" is yours too and you just need client IP there - you can pass just another POST
parameter with value from global array $_SERVER["REMOTE_ADDR"]
But if you need to make request from client IP - you should use iframe, as Pekka said.
You can also set up a php script that will proxify your call.
In the same domain, put a php script that will catch the post args, and resend it thru a curl call. then print the result that will catched by your jquery ajax call.
yes. use a curl script to post the image but then what? How do I get the results?
<form action="upload.php" method="post" enctype="multipart/form-data">
<input type="file" name="file" />
<input type="submit" name="sub" value="upload"/>
</form>
<?php
ini_set('display_errors',1);
error_reporting(E_ALL);
if($_POST['sub'])
{
if ((($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["file"]["type"] == "image/pjpeg")))
{
if ($_FILES["file"]["error"] > 0)
{
echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
}
else
{
//set POST variables
$url = 'http://img.savvylist.com/';
$contents = $_FILES["file"]["tmp_name"];
//get image file as contents.
$fields = array(
'filetype'=>'jpg',
'fileid'=>'test_suite:adam:head.jpg',
'content'=>$contents
);
//url-ify the data for the POST
$fields_string = '';
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
rtrim($fields_string,'&');
//open connection
$ch = curl_init();
//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_POST,count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string);
//execute post
$result = curl_exec($ch);
//close connection
curl_close($ch);
}
}
}
?>
Now what?
精彩评论