Solved

Redirect with curl

Posted on 2007-11-24
8
12,813 Views
Last Modified: 2013-12-13
How to redirect with curl.

What's wrong with my code.

<?
curl_init();
curl -L google.com;

?>
0
Comment
Question by:johnladm
  • 5
  • 2
8 Comments
 
LVL 21

Expert Comment

by:nizsmo
ID: 20344536
may i ask, why not just use:

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

as this is probably more effective.
0
 
LVL 54

Accepted Solution

by:
b0lsc0tt earned 200 total points
ID: 20344701
johnladm,

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.

b0lsc0tt
0
 

Author Comment

by:johnladm
ID: 20344801

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

b0lsc0tt:
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.
0
 

Author Comment

by:johnladm
ID: 20344809
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.
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:johnladm
ID: 20344884
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.


0
 
LVL 21

Assisted Solution

by:nizsmo
nizsmo earned 50 total points
ID: 20344894
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?
0
 

Author Comment

by:johnladm
ID: 20345873
The header never out put anything  to the browser out if its is using CURL.
0
 

Author Comment

by:johnladm
ID: 20346364
I got it. Yahoo!!!
Trick turn the result into string then redirect from there.
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to count occurrences of each item in an array.
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.

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

24 Experts available now in Live!

Get 1:1 Help Now