Manipulating POST data on a remote script

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ajayahmed
Forum Newbie
Posts: 1
Joined: Fri Aug 21, 2009 10:35 pm

Manipulating POST data on a remote script

Post by ajayahmed »

Hi Team,

I've tried searching this forum, google and various other forums and haven't found anything relative to this issue. There is a website that sells DVDs and has a search feature which is heavily coded and can't be accessed via a mobile browser so I stripped down the coding and came up with a simple HTML form. The form works fine but it loads up their search results which has a lot of irrelevant information which I want to strip down.

Is it possible to post to a remote site but return the data to a variable (so I can maniuplate)? If so how would I go about doing this? I've just found this website which is close to it but it uses javascript http://www.weberdev.com/get_example-3694.html

Thanks in advance,

Ajay
User avatar
susrisha
Forum Contributor
Posts: 439
Joined: Thu Aug 07, 2008 11:43 pm
Location: Hyderabad India

Re: Manipulating POST data on a remote script

Post by susrisha »

i would refer

Code: Select all

 
curl
 
to do ur posting the data. You will have options to get the data from the form that you posted and will be able to manipulate. Here is an example code

Code: Select all

 
// Set the URL that will handle the POST variables
$url ='link'; //put the action link for the search.
 
// Set the post variables string you want
$string='searchitem=blah&category=something';//this is just example of post string
 
// Initialize cURL
$ch = curl_init();
 
// Set the URL
curl_setopt($ch, CURLOPT_URL, $url);
 
// Accept cookies
curl_setopt($ch,CURLOPT_COOKIEFILE,1);
//Wait for 2 seconds while trying to connect
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 2);
 
 
// Submit our POST values (EG: $string)
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $string);
//Return string
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
 
 
// Execute...
$output = curl_exec($ch);
// now the whole data is got into $output variable. Do all the manipulations tou want to and display results
 
 
curl_close($ch);
 
Post Reply