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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T19:39:09+00:00 2026-06-07T19:39:09+00:00

I need to download an xml file using PHP. I am able to read

  • 0

I need to download an xml file using PHP. I am able to read the contents of file by setting following options when making a curl call to it.

curl_setopt ($http, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt ($http, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($http,CURLOPT_USERAGENT,'XYZ');

As evident from above snippet I need to make VERIFYHOST as false and also need to set an explicit USERAGENT when making a call to read the file because the file is not publicly accessible and only a specific application can make call to read it (Web-Security techniques and stuff)

But how do I download the same file, I have tried readfile, fopen/fpassthru, file_get_contents but nothing seems to be working.
Readfile gives the error failed to open stream: HTTP request failed! HTTP/1.0 403 Forbidden

Is there a way to provide curl like options with fopen or readfile, I think that may be the easiest approach to solve this. I could not find much help in PHP documentation.

Please help.

  • 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-07T19:39:11+00:00Added an answer on June 7, 2026 at 7:39 pm

    You need to attach your special user-agent to the stream context.

    From http://www.php.net/manual/en/wrappers.http.php

    Allows read-only access to files/resources via HTTP 1.0, using the HTTP GET method. A Host: header is sent with the request to handle name-based virtual hosts. If you have configured a user_agent string using your php.ini file or the stream context, it will also be included in the request.

    Example #2 from the link above:

    <?php
    ini_set('user_agent', "PHP\r\nX-MyCustomHeader: Foo");
    
    $fp = fopen('http://www.example.com/index.php', 'r');
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to download an XML file, using HTTP protocol, to use it locally
I need a master computer to be able to download a predefined XML file
I download an XML-file, I generate using PHP, that looks similar to this <?xml
I am using the following methods to download an xml file private void LoadXMLFile()
I need to download Gmail emails using php api. there APIs for google. i
I need to download xml file from a secure link, and store the content
I need to download a Cab file from a Url into a stream. using
Need to login and download xml file from the below url : http://www.radionyhetene.net/download/nyheter/mp3/nyheter.xml I
I need to download a large file (2 GB) over HTTP in a C# console
I need to download file from FTP server and make some changes on it

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.