HI, I am using the copy() function to download a web page as shown in this example: $userAgent = $_SERVER['HTTP_USER_AGENT']; $context_options = array ( 'http' => array ( 'method' => 'GET', 'header'=> "User-Agent: $userAgent" ) ); $context = stream_context_create($context_options); copy("http://www.example.com", "test/test.html", $context); However, contrary to the PHP document for the copy() function: bool copy ( string $source , string $dest [, resource $context ] ) it returns the following error: Warning: Wrong parameter count for copy() in /var/www/printer/ test2.php on line 17 The copy() works fine except when the third parameter is included but, in this case it returns http code 403 because the User-Agent isn't specified. Is it possible to include the third parameter hence, resource $context as stated in the documentation, is this a bug, or is there something wrong with my code? I am using Ubuntu/Linux 7.04 and php 5.2.1. Thanks, Carl http://www.gaihosa.com
Hello, According to the PHP Docs: http://uk.php.net/copy As you are running 5.2.1, it does not have context support. Jay
Actually, I think I found out why this is happening. I didn't add the line returns in the array. Something I over looked. In the mean I wrote some new code that uses fopen() and get_stream_context() to do the same thing. IT actually seamed to produce a few less timeouts and other connection errors. Thanks for the replies, Carl 1. $context_options = array ( 2. 'http' => array ( 3. 'method' => 'GET', 4. 'header'=> "User-Agent: $userAgent \r\n" 5. 6. ) 7. ); http://www.gaihosa.com
That's not what's causing the error. Read what jayshah said, you need to upgrade your PHP version. You have 5.2.1, context was added in 5.3.0. If you can't upgrade it or can't get your host to, drop the $context portion or use file_get_contents().