KSquared Posted October 18, 2006 Share Posted October 18, 2006 Hello All,Anyone help me with CURL? Here is the issue: I need to send some values through the post method from an interim page. The form is submitted, data written to csv (which is working fine), then I need to send the same data to an email collection page outside of my domain. The following script returns a page that says "Object Moved to here", "here" being a link to the actual page that needs to load. http://www.serenocanyon.com/thankyou.htm [code]$SubscribeDate = date("F j, Y"); $fname = $_POST['fname']; $lname = $_POST['lname']; $emailAdd = $_POST['emailadr']; $source = $_POST['source']; $thx = $_POST['thx']; //http://www.serenocanyon.com/thankyou.htm $err = $_POST['err']; $usub = $_POST['usub']; $postArray = "First Name=".urlencode($fname)."&Last Name=".urlencode($lname)."&Email Address=".urlencode($emailAdd)."&Source=".urlencode($source)."&thx=".urlencode($thx)."&err=".urlencode($err)."&usub=".urlencode($usub)."&Subscribe Date=".urlencode($SubscribeDate); $url = "http://cl.exct.net/subscribe.aspx?lid=1220593"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,$url); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $postArray); $results = curl_exec($ch); echo $results; curl_close($ch);[/code]Why is this happening? Any help would be MUCH appreciated. Thanks,Keith Quote Link to comment Share on other sites More sharing options...
xsist10 Posted October 18, 2006 Share Posted October 18, 2006 You're problem looks like you're URL has parameters in it.[code]<?php$url = "http://cl.exct.net/subscribe.aspx";$postArray = "lid=1220593&First Name=". urlencode($fname) ."&Last Name=". urlencode($lname) ."&Email Address=". urlencode($emailAdd) ."&Source=". urlencode($source) ."&thx=". urlencode($thx) ."&err=". urlencode($err). "&usub=". urlencode($usub) ."&Subscribe Date=". urlencode($SubscribeDate); // Initialize CURL$ch = curl_init($url);// Set "Fail on Error" to Truecurl_setopt($ch, CURLOPT_FAILONERROR, 1);// Set "Allow Redirects" to Truecurl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);// Set "Timeout" to 3 secondscurl_setopt($ch, CURLOPT_TIMEOUT, 3);// Set "POST" as Message Methodcurl_setopt($ch, CURLOPT_POST, 1);// Set POST Informationcurl_setopt($ch, CURLOPT_POSTFIELDS, $postArray); // Use Output Buffering (Return Transfer doesn't work properly?)ob_start();// Execute CURLcurl_exec($ch);// Get Information about the transaction$info = curl_getinfo($ch);// Close CURL Sessioncurl_close($ch);// Store Data from Output Buffer$data = ob_get_contents();// Clear Output Bufferob_end_clean();//200 is meaning valid url as 404 meaning "not found on this server" etc..if ($info['http_code']==200) { echo "success";} else { echo "failed";}?>[/code] Quote Link to comment Share on other sites More sharing options...
KSquared Posted October 18, 2006 Author Share Posted October 18, 2006 Thanks xsist,You have no idea how long I have been trying to figure this out... I owe u big!I got a "success" return. So... to actually load the thankyou page I edited the following:[code]if ($info['http_code']==200) { header("Location:http://www.serenocanyon.com/thankyou.htm");} else { header("Location:http://www.serenocanyon.com/error.htm");}[/code]Even though, the email collection page should send back the "return url" (being the thankyou.htm page) and load it, it does not, which is why I edited the above.Does that seem correct? Quote Link to comment Share on other sites More sharing options...
Destruction Posted October 18, 2006 Share Posted October 18, 2006 If the page you're posting to sets a cookie and you don't use CURLs cookie jar parameters, RETURNTRANSFER will not work because the page will be expecting a cookie and it will not be sent back. Please read the manual as regards examples using RETURNTRANSFER. This is important for the FOLLOWLOCATION parameter.Hope this helps,Dest Quote Link to comment Share on other sites More sharing options...
xsist10 Posted October 18, 2006 Share Posted October 18, 2006 [quote author=KSquared link=topic=111908.msg453850#msg453850 date=1161185787]Even though, the email collection page should send back the "return url" (being the thankyou.htm page) and load it, it does not, which is why I edited the above.Does that seem correct?[/quote]All the results from the page will be in $data. You can parse this for a result. Quote Link to comment Share on other sites More sharing options...
KSquared Posted October 18, 2006 Author Share Posted October 18, 2006 Actually, I tried to parse $data but maybe Im parsing wrong.If I do a var_dump($data), or print_r($data)<-- this give blank white page, it simply renders the thankyou.htm page on the email_updates.php page (where the curl script lives), it does not redirect to the actual thankyou.htm page.However, i did the following with $info and it seems to work great, its returning correctly, even the error pages are now rendering correct with the correct errorcodes:[code]if($info['http_code']==200){ header("Location:".$info['url']);}else{ header("Location:".$info['url']);}[/code]Just want to be sure its ok to parse the $info instead of $data? Quote Link to comment 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.