Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 12969
  • Last Modified:

Redirect with curl

How to redirect with curl.

What's wrong with my code.

curl -L google.com;

  • 5
  • 2
2 Solutions
may i ask, why not just use:

header("Location: http://www.google.com");

as this is probably more effective.

A redirect isn't done with cUrl even with the -L switch.  That tells cUrl to follow redirects not to redirect.

In PHP the way to redirect is to use script like nizsmo suggested.  Using the Location header will stop the script and send the browser or page to the URL.  Using cUrl is a way to get content from other pages/sites and the -L switch would allow the process to still happen if the URL used in cUrl goes to a server redirect.

I hope this clears up the difference and use for each.  Let me know if you have any questions or need more information.

johnladmAuthor Commented:

I tested that the
header("Location: http://www.google.com"); will not work any where with the curl.

I am a little confusing  with this statement, can you please explain in another term.
"Using cUrl is a way to get content from other pages/sites and the -L switch would allow the process to still happen if the URL used in cUrl goes to a server redirect."

Any I am able to connect to GET and POST contents to API script.
I really want to make sure  the data is posted on my database server and then redirect to the origional page.
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.

johnladmAuthor Commented:
If I use the
<meta http-equiv="refresh" content="1;url=google.com">

then my page will redirect to the origional page but that is not a good idea to do it.
johnladmAuthor Commented:
I think if i use the xml to out put the result then use some script to dectect the fields then I should be able to redirect on the curl page.

If possible, can you guys plz show me a little on how  to design a universal xml content ?
and call the data in the xml content.

hmm sorry was away for a while. So how come the header  function does not work for you? has something been written to the browser already before you call the header function?
johnladmAuthor Commented:
The header never out put anything  to the browser out if its is using CURL.
johnladmAuthor Commented:
I got it. Yahoo!!!
Trick turn the result into string then redirect from there.

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 5
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now