Stormcrow Posted September 8, 2011 Share Posted September 8, 2011 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! Quote Link to comment https://forums.phpfreaks.com/topic/246711-getting-html-source-code-with-curl-with-post-varibales/ Share on other sites More sharing options...
Stormcrow Posted September 8, 2011 Author Share Posted September 8, 2011 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); Quote Link to comment https://forums.phpfreaks.com/topic/246711-getting-html-source-code-with-curl-with-post-varibales/#findComment-1267024 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.