Jump to content

curl response and redirect


lightlydone

Recommended Posts

Hi, I'm posting a form using curl:

 

<?php

//create the final string to be posted using implode()
$post_str = implode ('&', $post_items);
		  
//Initialize cURL and connect to the remote URL 
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://leads..html' );

//Instruct cURL to do a regular HTTP POST
curl_setopt($ch, CURLOPT_POST, TRUE);

//Specify the data which is to be posted
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_str);

//Tell curl_exec to return the response output as a string
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);

//Follow 302 redirect
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);  

// Timeout in seconds
curl_setopt($ch, CURLOPT_TIMEOUT, 30);

//verify https
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);

//Execute the cURL session
$response = curl_exec($ch );

//Close cURL session and file
curl_close($ch);

echo $response;

$resp = explode("\n\r\n", $response);
$header = explode("\n", $resp[0]);

echo "<pre>";
print_r($header);
echo "</pre>";

?>

 

The response is:

 

success:  https://www-somesite.html

 

or

 

Array

(

    [0] => success: https://www-somesite.html

)

 

My question is how to get the returned URL and redirect the user to it?

 

Probably easy but seems to be beyond my very limited php knowledge.

 

Thanks.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.

×
×
  • 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.