Why doesn't cURL actually take the browser to this URL?
Posted on 2011-04-19
I am using cURL in PHP to redirect a browser to a page along with some specified POST values. I want the browser to be directed to the URL I specify in my code, and not just 'fetch' it. I thought that the CURLOPT_FOLLOWLOCATION would do this, but it does not. I am running Windows 2003 Server edition, and have enabled everything on the php.ini files to ensure curl will work. It does for the most part, but the browser never actually gets redirected.
So while this works (without sending my POST values to the URL):
Header("HTTP/1.1 301 Moved Permanently");
This does not
//create a new cURL resource
$ch = curl_init();
// setup the URL and its options
curl_setopt($ch, CURLOPT_URL, "http://www.mydomain.com/demo/");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "redirect=ftsconnect");
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
Any ideas how I can ensure that cURL actually redirects the browser to http://www.mydomain.com/demo?
Thank you for your time and help!