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 7164347
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T14:03:38+00:00 2026-05-28T14:03:38+00:00

I am trying to parse a page which contains some links. These links, if

  • 0

I am trying to parse a page which contains some links. These links, if followed, will redirect to some files to download.

For example, <a href="http://example.com/file.php"> Download </a> which redirects to <a href="http://example.com/1.pdf".

I don’t want to download the file, I just want to get the file link (int this case http://example.com/1.pdf).

I am trying this:

curl_setopt($ch, CURLOPT_RETURNTRANSFER, FALSE);     // Return in string
curl_setopt($ch, CURLOPT_URL, $url);
curl_exec($ch);
var_dump(curl_getinfo($ch));

But, it gives me the file contents.

Does anyone have any idea how to this?

==EDIT==
Thank you guys. I solved it like this:

curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLINFO_HEADER_OUT, TRUE);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, TRUE);
curl_setopt($ch, CURLOPT_NOBODY, TRUE);
curl_exec($ch);
$info = curl_getinfo($ch);

Now, $info contains the header and I can the link from it.

  • 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-05-28T14:03:39+00:00Added an answer on May 28, 2026 at 2:03 pm

    The reason the output is being sent to the screen is because you’re telling cURL to do so. If you want to store the response in a variable the following line:

    curl_setopt($ch, CURLOPT_RETURNTRANSFER, FALSE);

    should read:

    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);

    Then, actually retrieve the returned output from curl_exec like so:

    $output = curl_exec($ch);

    Once you have the returned HTML content from the remote page in the $output variable you can use DOMdocs or regex (but preferably DOM) to parse out any information you want.

    UPDATE

    I can’t tell because the question is vaguely worded: is there actually a Location header redirect happening? If so, you’ll want to do as @heiko suggests to prevent cURL from following the redirect and retrieve the headers. Then you can easily parse the contents of the location header:

    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, FALSE);
    curl_setopt($ch, CURLINFO_HEADER, TRUE); // add header output
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to make a web scraper that will parse a web-page of publications
Trying to parse an HTML document and extract some elements (any links to text
I'm trying to traverse an AJAX response, which contains a remote web page (an
I am trying to parse html page and I am facing a problem which
I'm trying to parse a page for which I've to first log into that
I'm trying to parse some parts of an HTML page but I have problems
I'm trying to parse a page that has different sections that are loaded with
i'm trying to parse an html page and get the first occurrence of a
I am trying to use html5lib to parse an html page in to something
Trying to parse some XML but apparently this is too much for a lazy

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.