[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

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

Posted on 2011-04-19
7
Medium Priority
?
431 Views
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");
Header("Location: http://www.mydomain.com/demo/");

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);
curl_exec($ch);
curl_close($ch);


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!
0
Comment
Question by:ariestav
  • 3
  • 2
  • 2
7 Comments
 
LVL 8

Expert Comment

by:Rik-Legger
ID: 35425423
You cannot do this with cUrl of a header location redirect.
You could use a auto submit form using javascript?
0
 
LVL 4

Author Comment

by:ariestav
ID: 35425472
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?

Thanks!
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 35425515
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
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 8

Accepted Solution

by:
Rik-Legger earned 2000 total points
ID: 35425562
<form method="post" action=""http://www.mydomain.com/demo/" id="form" name="form">
<input type="hidden" name="redirect" value="ftsconnect">
</form>
<script language='javascript' type='text/javascript'>document.getElementById('form').submit();</script>

Open in new window

0
 
LVL 4

Author Comment

by:ariestav
ID: 35425593
Thank you!  I will give that a shot and report back.
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 35429417
@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
0
 
LVL 4

Author Closing Comment

by:ariestav
ID: 35692024
Sorry for not reporting back earlier.  Your solutions was perfect!
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
This holiday season, we’re giving away the gift of knowledge—tech knowledge, that is. Keep reading to see what hacks, tips, and trends we have wrapped and waiting for you under the tree.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The is a quite short video tutorial. In this video, I'm going to show you how to create self-host WordPress blog with free hosting service.
Suggested Courses
Course of the Month18 days, 6 hours left to enroll

830 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