Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cURL , get redirect url to a variable

Tags:

redirect

php

curl

I'm using curl to fill a form. After completion of the post the other script which handles the form is redirecting to another URL. I want to get this redirect URL into a variable.

like image 260
Vamsi Krishna B Avatar asked Oct 31 '10 10:10

Vamsi Krishna B


People also ask

How do I redirect a URL in curl?

To follow redirect with Curl, use the -L or --location command-line option. This flag tells Curl to resend the request to the new address. When you send a POST request, and the server responds with one of the codes 301, 302, or 303, Curl will make the subsequent request using the GET method.

How do you get a redirected URL?

Click the URL Redirects tab. In the upper right, click Add URL redirect. In the right panel, select the Standard or Flexible redirect type. A standard redirect is used to redirect one URL to another.

Does Curl handle redirects?

In curl's tradition of only doing the basics unless you tell it differently, it does not follow HTTP redirects by default. Use the -L, --location option to tell it to do that. When following redirects is enabled, curl will follow up to 50 redirects by default.

How can I get URL redirect in PHP?

Answer: Use the PHP header() Function You can simply use the PHP header() function to redirect a user to a different page. The PHP code in the following example will redirect the user from the page in which it is placed to the URL http://www.example.com/another-page.php . You can also specify relative URLs.


1 Answers

Easy way to find the redirected url (if you don't want to know in advance)

$last_url = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL); 
like image 133
EGL 2-101 Avatar answered Sep 29 '22 10:09

EGL 2-101