PHP Post data with Fsockopen

There are many small errors in your code. Here’s a snippet which is tested and works. <?php $fp = fsockopen(‘example.com’, 80); $vars = array( ‘hello’ => ‘world’ ); $content = http_build_query($vars); fwrite($fp, “POST /reposter.php HTTP/1.1\r\n”); fwrite($fp, “Host: example.com\r\n”); fwrite($fp, “Content-Type: application/x-www-form-urlencoded\r\n”); fwrite($fp, “Content-Length: “.strlen($content).”\r\n”); fwrite($fp, “Connection: close\r\n”); fwrite($fp, “\r\n”); fwrite($fp, $content); header(‘Content-type: text/plain’); while (!feof($fp)) … Read more

How to check if a file exists from a url

You don’t need CURL for that… Too much overhead for just wanting to check if a file exists or not… Use PHP’s get_header. $headers=get_headers($url); Then check if $result[0] contains 200 OK (which means the file is there) A function to check if a URL works could be this: function UR_exists($url){ $headers=get_headers($url); return stripos($headers[0],”200 OK”)?true:false; } … Read more