Pass variables between PHP and JSP with cURL - php

I am working on an online shop payment system and have to deal with both JSP and PHP file. Here is the partial flow of the transaction:
PHP gets the encrypted string from $_REQUEST & passes it to JSP by cURL.
JSP decrypts it by calling corresponding API function.
JSP passes the decrypted variables back to PHP.
PHP receives the variables and updates the database.
PHP display response message.
Here is the PHP code:
<?php
$data = $_REQUEST['String'];
$url = "http://demo:8000/decrypt.jsp";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, "String=$data");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec ($ch);
curl_close ($ch);
//print $result;
//update database...
?>
I have done some testing and the encrypted string can be successfully passed to JSP by cURL. However, I have no idea how to pass the JSP variables back to the same PHP file.
Is there any solution for this problem?

Related

php post raw data - follow post URL

i need to post raw data (XML) to an external site, the XML data is good to go, and is working with the below example...
I am using PHP / cURL
normally i do this by cURL, but in this instance, i need to redirect the client to the URL with the post data...
It works using the below code, but it won't redirect the user to the $URL, this method just prints the data while still being in the script on the same server.
eg:
Post from site1.com to site2.com, the below method keeps the client on site1, but needs to redirect the user to site2.com with the raw post data...
$ch = curl_init($URL);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_xml);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
$val = curl_exec($ch);
curl_close($ch);
i have searched all-over but cannot find a method where it functions as a "regular" form submit where the user is redirected to the URL which the data is posted to... but with RAW post data.

Curl request not working to use hasoffers api

I am using curl request to hit the has-offers conversion url from my sevrver with the help of curl but it is not working.But when I call the same URL using a browser, it works.Is they can block CURL requests?.I am not getting why, is there any port blocking issue.
Below is php code to call url using curl request.
<?php
function curl_get_contents($url)
{
$ch = curl_init();
$timeout = 5;
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
$url="http://paravey.go2cloud.org/aff_l?offer_id=12&aff_id=1000";
$contents = curl_get_contents($url);
echo $contents;
?>
Please help me thanks in Advance
The url you are curling is a pixel tracking url:
http://paravey.go2cloud.org/aff_l?offer_id=12&aff_id=1000
The aff_l endpoint looks for a cookie with session information (hence why it works in the browser).
If you want to create conversions with server side code, you will need to store the session identifier (the transaction_id) in your system and use the aff_lsr endpoint to send that data to HasOffers to trigger a conversion.
The url for this would look like this:
http://paravey.go2cloud.org/aff_lsr?transaction_id= VALUE
Where Value is the session identifier you have stored.
I would ask the HasOffers support team if you have more issues with this.

Codeigniter Session Lost When Using CURL

I am trying to get CI session from an external file. I have a page on CI that dumps the current session. When i access direct it operates as expected. However when i access via CURL it returns nothing. I believe CI session is lost when sending request using CURL.
My question is how do i send this session data together with my curl request.
The code i am using is as below.
$url = "http://localhost/cdmcl/dashboard/getsession";
$ch = curl_init();
$timeout = 5;
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$data = curl_exec($ch);
curl_close($ch);
echo $data;
You need to set CURLOPT_COOKIEFILE so that cURL saves its cookies into a file.
So, for Code Igniter you have to write like this:
$this->curl->option(CURLOPT_COOKIEFILE,'cookies_1.txt');

CURl not returning an entire page

I am using CURl to retrieve a page for a small search engine project I am working on, but on some pages it's not retrieving the entire page.
The function that I have setup is:
public function grabSourceCode($url) {
// Try and get source code using #file_get_contents
$ch = curl_init();
$timeout = 50;
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_USERAGENT,'NameBot/0.2');
$source_code = curl_exec($ch);
curl_close($ch);
return $source_code;
}
and I am retrieving the page using:
$Crawler->grabSourceCode('https://sedo.com/search/searchresult.php4?keyword=cats&language_output=e&language=e')
on this page I get everything, but on this page, I only get part of the page.
I have tried using file_get_contents() but that has the same results.
It seem's to be an issue with dynamic loading of the page, when I run the browser in JavaScript blocking mode it shows the same results as the CURl function.
Is there anyway to do this in PHP, or would I have to look at another language, such as JavaScript?
Thanks, Daniel

How do I pass XML data as a PAYLOAD on the stream?

I'm new to XML, and usually use JSON to pass data. I am working with a new system, and this was part of their instructions to me about passing data:
The XML content then can be sent as either PAYLOAD on the stream or as an additional parameter. If the latter is done, the parameter name is RequestXML
I'm not sure what this means? I'm afraid if I pass it as a parameter, but I have a lot of text, it will make the URL too long, so I'd like to do the PAYLOAD option. I'm using PHP and Jquery to generate the array. I can create an XML file using PHP and have it properly formatted as XML, but sending it across is confusing me.
What do I need to do to get it sent as a PAYLOAD?
You'll likely just want to send a POST HTTP request. Here's an example using the curl library:
<?php
$url = "https://example.com/service";
$xml = "<foo />";
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml'));
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
curl_close($ch);
?>

Categories