Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7711035
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T01:16:30+00:00 2026-06-01T01:16:30+00:00

I am developing php application with cURL library. I would like to get redirect

  • 0

I am developing php application with cURL library.

I would like to get redirect url (in case 301 or 302 http code). In Windows it is simple, I just need to call curl_getinfo($ch). This methods returns associative array with redirect_url, which I am using later.

I have problem when I moved my application to linux server. Such method (curl_getinfo) returns array too, but there is no “redirect_url” index. I though I could try to read headers as a string. I set

curl_setopt(CURLOPT_HEADERFUNCTION, callback) 

and save response headers as a string. Then I use simple parser to get fields I am interested in. But now I have another problem. Redirect url (http header LOCATION) returns relative url (whereas in Windows it is absolute).

Why there are differences in windows cURL and linux one? What can I do to make this application resistant to OS changes? And finally, how can I get this field (redirect url) as an absolute url in linux.

Thanks for your help 🙂

Sample from Windows:

Array
(
[url] => http:// wiadomosci.wp.pl/kat,1342,title,Ciag-dalszy-sporu-wokol-poslow-PiS-Nie-moge-tego-zrobic,wid,13927471,wiadomosc.html
[content_type] => text/html
[http_code] => 302
[header_size] => 2407
[request_size] => 384
[filetime] => -1
[ssl_verify_result] => 0
[redirect_count] => 0
[total_time] => 0.046
[namelookup_time] => 0
[connect_time] => 0.015
[pretransfer_time] => 0.015
[size_upload] => 0
[size_download] => 0
[speed_download] => 0
[speed_upload] => 0
[download_content_length] => 0
[upload_content_length] => 0
[starttransfer_time] => 0.046
[redirect_time] => 0
[certinfo] => Array
    (
    )

[redirect_url] => http:// wiadomosci.wp.pl/kat,1342,title,Ciag-dalszy-sporu-wokol- poslow-PiS-Nie-moge-tego-zrobic,wid,13927471,wiadomosc.html?ticaid=1d436
)

and windows:

Array
(
[url] => http:// wiadomosci.wp.pl/kat,1342,title,Ciag-dalszy-sporu-wokol-poslow-PiS-Nie-moge-tego-zrobic,wid,13927471,wiadomosc.html
[content_type] => text/html
[http_code] => 302
[header_size] => 2425
[request_size] => 384
[filetime] => -1
[ssl_verify_result] => 0
[redirect_count] => 0
[total_time] => 0.023254
[namelookup_time] => 0.001938
[connect_time] => 0.004836
[pretransfer_time] => 0.004847
[size_upload] => 0
[size_download] => 0
[speed_download] => 0
[speed_upload] => 0
[download_content_length] => 0
[upload_content_length] => 0
[starttransfer_time] => 0.023068
[redirect_time] => 0
[certinfo] => Array
    (
    )
)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T01:16:31+00:00Added an answer on June 1, 2026 at 1:16 am

    There is an alternative solution that will work on every (currently supported) os.

    You can ask curl to follow the redirect and limit it to one depth and then use the url key from curl_getinfo($ch);

    Example:

    <?php
    
    $url         = 'http://jigsaw.w3.org/HTTP/300/301.html';
    $expectedUrl = 'http://jigsaw.w3.org/HTTP/300/Overview.html';
    
    $ch = curl_init();
    curl_setopt( $ch, CURLOPT_URL, $url );
    curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, true );
    curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
    curl_setopt( $ch, CURLOPT_MAXREDIRS, 1);
    
    $content = curl_exec( $ch );
    $response = curl_getinfo( $ch );
    curl_close ( $ch );
    
    if ($response['url'] == $expectedUrl)
        echo "I have the correct redirect url\n";
    else
        echo "I do not have the correct redirect url\n";
    

    If you just want the end url, no matter how many redirects there may be, you can remove the CURLOPT_MAXREDIRS option (or set it high to prevent loops)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We are developing a web application using php/java servlets. i would like to pass
I'm developing a simple PHP database application for internal use but would like to
I'm developing a PHP application that uses HTTP response codes for communication as well
At work, we are developing an PHP application that would be later re-programmed into
I am developing an URL bookmark application (PHP and MySQL) for myself. With this
I am developing a PHP web application for photographers. A normal process would be
I am developing a small part of a PHP application with some python code.
I am developing a php application. Is it possible to get active sessions and
I'm currently developing a PHP application that's using an Access database as a backend.
I am developing a PHP application using our XAMPP setup as a test server.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.