Is there a way to get file_get_contents return page URL

Source: Internet
Author: User
Use file_get_contents with a cookie to access a remote page, but the page jumps to another page, now the question is whether to get the URL of the post-jump page? I know that using get_headers is a way to get headers such as cookies, but how do I get a URL?


Reply to discussion (solution)

Get_headers can also get the URL of the jump

File_get_contents automatically jumps to the new destination URL based on the HTTP header's instructions
If the destination URL has a jump, there is a location entry in the result of the get_headers.
And Get_headers will also track the final target, so the value of the last location item is what you want.

$a = Get_headers ($url, 1), if (Isset ($a [' Location ')}) {  $url = Is_array ($a [' location '])? Array_pop ($a [' Location ']): $a [' Location '];}

You know the original link, open directly in the browser, do not know it jumps to which link?

File_get_contents automatically jumps to the new destination URL based on the HTTP header's instructions
If the destination URL has a jump, there is a location entry in the result of the get_headers.
And Get_headers will also track the final target, so the value of the last location item is what you want.

$a = Get_headers ($url, 1), if (Isset ($a [' Location ')}) {  $url = Is_array ($a [' location '])? Array_pop ($a [' Location ']): $a [' Location '];}



But there's no location in the header. In fact, I do is for discuz automatic post, after the post to jump to the content page, now I want to get new posts Id,url inside there is this.

He had only one verse 200, so it didn't happen. HTTP Jump
Instead, include the posts page directly on the form acceptance page
You can only analyze the page content to find out the post ID
In fact, it's simple: Find the code for the response.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.