Why doesn't cURL actually take the browser to this URL?

Posted on 2011-04-19
Last Modified: 2012-06-27
Hi There,

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, "");
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

Thank you for your time and help!
Question by:ariestav
    LVL 8

    Expert Comment

    You cannot do this with cUrl of a header location redirect.
    You could use a auto submit form using javascript?
    LVL 4

    Author Comment

    Hi Rik-Legger,

    Thank you for the suggestion regarding a auto-submit form.  How does one go about that?  Is there a resource you can point me to for creating an auto-submit javascript form?

    LVL 107

    Expert Comment

    by:Ray Paseur
    Can you please tell us why you want to do this?  If we understand what you're trying to achieve we may be able to offer an easier suggestion.  Thanks, ~Ray
    LVL 8

    Accepted Solution

    <form method="post" action=""" id="form" name="form">
    <input type="hidden" name="redirect" value="ftsconnect">
    <script language='javascript' type='text/javascript'>document.getElementById('form').submit();</script>

    Open in new window

    LVL 4

    Author Comment

    Thank you!  I will give that a shot and report back.
    LVL 107

    Expert Comment

    by:Ray Paseur
    @ariestav:  After you give it a shot, please tell us why you want to do this, thanks.  If we understand what you are trying to achieve we may be able to offer an easier suggestion.  Thanks, ~Ray
    LVL 4

    Author Closing Comment

    Sorry for not reporting back earlier.  Your solutions was perfect!

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Maximize Your Threat Intelligence Reporting

    Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

    Part of the Global Positioning System A geocode ( is the major subset of a GPS coordinate (, the other parts being the altitude and t…
    I've been asked to discuss some of the UX activities that I'm using with my team. Here I will share some details about how we approach UX projects.
    This tutorial walks through the best practices in adding a local business to Google Maps including how to properly search for duplicates, marker placement, and inputing business details. Login to your Google Account, then search for "Google Mapmaker…
    The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now