i'm working on project have include third party application in our system. application transmitts parameters php file using jquery ajax when calling index.php. exact function looks this:
$.ajax( { type : "post", cache : false, crossdomain : false, async : true, url : "/somwhere/somefile.php", data : "msg=37120&hello=true&usrid=1" )};
i'm not experienced ajax @ far can see in end parameters "msg=37120&hello=true&usrid=1"
postet on somefile.php. want post variables directly onto somefile.php using php instead of js/ajax.
after researches found following solution send post data directly somefile.php
:
$url = "/somwhere/somefile.php"; $ch = curl_init( $url ); curl_setopt( $ch, curlopt_post, 1); curl_setopt( $ch, curlopt_postfields, "msg=37120&hello=true&usrid=1"); $response = curl_exec( $ch );
unfortunately not working @ all. no data arrives when i'm executing code block. i've no idea i'm doing wrong. can tell me whats mistake here? or there better way how this?
edit: sorry -- posted get, below code post.
this code use works well:
$cookie="cookie.txt"; $useragent="mozilla/4.0 (compatible; msie 6.0; windows nt 5.1; sv1; .net clr 2.0.50727; .net clr 3.0.04506.30)"; $data=array( "field1" => 'data1', "field2" => 'data2', "submit" => 'true' ); $cr = curl_init($url); curl_setopt($cr, curlopt_returntransfer, true); // returned value string (dont put screen) curl_setopt($cr, curlopt_useragent, $useragent); // spoof user-agent browser user on (and accessing php $ curl_setopt($cr, curlopt_cookiejar, $cookie); // use cookie.txt storing cookies curl_setopt($cr, curlopt_cookiefile, $cookie); // use cookie.txt storing cookies curl_setopt($cr, curlopt_post, true); // tell curl posting data curl_setopt($cr, curlopt_postfields, $data); // post data in array above $output = curl_exec($cr);
Comments
Post a Comment