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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:21:25+00:00 2026-05-23T16:21:25+00:00

I am requesting a website like (Rapidshare) that in response gives me either the

  • 0

I am requesting a website like (Rapidshare) that in response gives me either the requested file or some HTML telling that I need to wait xx seconds before I download file.
at
I am confused how to code this scenario.

Now if I do posting using an HTML form, setting some fields in it and then auto submitting it using Javascript to the target site. If it is success, user is prompted with if he wants to download that fiel, and if it is fail for some reason like if user need to wait, it takes user to THAT site URL.

to avoid user redirecting to target site error page. I am using CURL, that sends POST request and reads response.
Now, problem is, if reponse of CURL request is a file, page keeps loadin until and unless whole file recieved in response is download on server and stored in that variable.

this function That makes curl request at $url with $headerz as header values, and $encoded are request parameters

 function makeCurlPostRequest($url, $headerz, $encoded){
       $ch = curl_init();
       curl_setopt($ch, CURLOPT_URL, $url);
       curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
       if($headerz!=null)
       curl_setopt($ch, CURLOPT_HTTPHEADER, $headerz);
       curl_setopt($ch, CURLOPT_HEADER, 1);
       curl_setopt($ch, CURLOPT_POST, 1);
       if($encoded!=null)
       curl_setopt($ch, CURLOPT_POSTFIELDS, $encoded);
       curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
       curl_setopt($ch, CURLOPT_AUTOREFERER, 0);
       curl_setopt($ch, CURLOPT_REFERER, $url);
       $output = curl_exec($ch);
       curl_close($ch);
       return $output;
    }



 function checkUrl($file,$url,$headerz){
        $post_data = array ( "premium_acc" => "checked",
            "linkx" => "$file"
        );
        $encoded = '';
        foreach($post_data as $name => $value) {
          $encoded .= urlencode($name).'='.urlencode($value).'&';
        }
        $scrapHTML = makeCurlPostRequest($url, $headerz, $encoded);
        return $scrapHTML;
    }

CheckUrl, takes 3 parameters, $file link of file to download, $url url to request at and $headerz are header values.

Now I uploaded a test file

a.txt

with contents

ABCDABCDABCD

Then upon making a successful request and printing responce on Web browser using ti outputs this

HTTP/1.1 200 OK Date: Fri, 08 Jul 2011
07:25:43 GMT Server: Apache/2.2.16
(Debian) X-Powered-By:
PHP/5.3.3-7+squeeze1 Expires: Mon, 26
Jul 1997 05:00:00 GMT Last-Modified:
Fri, 08 Jul 2011 07:25:43GMT
Cache-Control: no-cache,
must-revalidate Pragma: no-cache
Content-Disposition: filename=”a.txt”
Connection: close Accept-Ranges: bytes
Content-Length: 1 Content-Type:
application/force-download
ABCDABCDABCD

Where ABCDABCDABCD is contents ot TXT file. if it is an audio file it outputs some random characters after downloading it completely.

I need to prompt this data to user to download instead of first saving it on server or in a variable.

is there a way, I can check responce header if returned is a file and if a file then prompt user to download.

any solution by this CURL method?

OR

  <form action="d.php" method="POST">
            <input type="hidden" name ="url" value="<?php echo $url;?>"/>
     <?php 
     foreach($scrapHTML->find('input') as $field) {
      $name = $field->name;
      $value = $field->value;
     ?>       
            <input type="hidden" name ="<?php echo $name;?>" value="<?php echo $value;?>"/>
            <?php
     }
            ?>
        </form>
        <script type="text/javascript">
            void(document.forms[0].submit());
    </script>

This HTML form sends request to target URL and on success prompts user with file to download but problem is in case of error it takes user to THAT website error or waiting page that I don’t want to be visible to user.

Please provide a solution, either using curl or using HTML form post.

regards,
aqif

  • 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-23T16:21:25+00:00Added an answer on May 23, 2026 at 4:21 pm
        $opts = array ( 'http' => array ( 'max_redirects' => 1, 'ignore_errors' => 1 ) );
        stream_context_get_default ( $opts );
        $headers = get_headers ( $url, true );
        if ( strstr ( $headers [ 'Content-Type' ], 'text/html' ) ){
           ....... DO YOUR CODE ..........
        }
    

    EDIT : Set this to send POST Variables

    $postdata = http_build_query(
        array(
            'var1' => 'some content',
            'var2' => 'doh'
        )
    );
    $opts = array('http' =>
        array(
            'method'  => 'POST',
            'header'  => 'Content-type: application/x-www-form-urlencoded',
            'content' => $postdata
        )
    );
       stream_context_get_default ( $opts );
        $headers = get_headers ( $url, true );
        if ( strstr ( $headers [ 'Content-Type' ], 'text/html' ) ){
           ....... DO YOUR CODE ..........
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am requesting the source code of a website like this: <? $txt =
There are many techniques to enforce strong passwords on website: Requesting that passwords pass
I need to scrape from a website that requires authentication, that is a user
We have an ASP.NET MVC website that a customer is requesting Active Directory single
Client is requesting a single track to be heard across the website. Generally I
I often have customer requesting changing properties, like the version history setting on all
My client is requesting that each simple product within a bundled product they are
If I have a resource that a requesting client doesn't have access to but
I need code in Perl for requesting and parsing ATOM and RSS feeds. Is
I'm requesting a webpage with sockets like this: Socket sock = null; PrintWriter out

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.