Jump to content

Getting html source code with CURL with POST varibales


Stormcrow
 Share

Recommended Posts

Hey guys,

 

First post here, so feel free to flame me if im violating the rules somehow.

 

So, the issue is this: i built an ebay listing creator for a customer. it conssists of a form with several fields being posted to a page that assembles everything into a listing (text, images, radio buttons etc.). now, what i want to do is to easily allow the customer to copy the compiled source code into the clipboard (or a txt file, doesnt really matters) - in order to easily copy it into ebay. I tried it with CURL, but all i get is the source without the posted information. I must be missing something there.

 

Any help would be appreciated, if you need links or codes iv's used, ill provide.

 

Thanks in advance!

Link to comment
Share on other sites

I found the solution. so posting here in case anyone else encountered the same situation. i used the following code on the preview page:

 

$ch = curl_init($sub_req_url);
$_SESSION['$encoded'] = '';
// include GET as well as POST variables; your needs may vary.
foreach($_GET as $name => $value) {
  $_SESSION['$encoded'] .= urlencode($name).'='.urlencode($value).'&';
}
foreach($_POST as $name => $value) {
  $_SESSION['$encoded'] .= urlencode($name).'='.urlencode($value).'&';
}
// chop off last ampersand
$_SESSION['$encoded'] = substr($_SESSION['$encoded'], 0, strlen($_SESSION['$encoded'])-1);
curl_setopt($ch, CURLOPT_POSTFIELDS,  $_SESSION['$encoded']);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_exec($ch);
curl_close($ch);

 

And i used this code on the output page that shows you the acutal source code including the POSTed variables:

 

        // create curl resource 
        $ch = curl_init(); 

        // set url 
        curl_setopt($ch, CURLOPT_URL, "http://scorpiocollections.com/ebay/preview.php"); 

        //return the transfer as a string 
	curl_setopt($ch, CURLOPT_POSTFIELDS,  $_SESSION['$encoded']);
	curl_setopt($ch, CURLOPT_HEADER, 0);
	curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 

        // $output contains the output string 
        $output = curl_exec($ch); 

        // close curl resource to free up system resources 
        curl_close($ch);

Link to comment
Share on other sites

This thread is more than a year old.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.