Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*fetches a page
- $url => url of the page,
- $data =>array(<param1>=><value1>,<param2>=><value2>....) storing get or post pvariables and values
- $cookie => array('cookieName1'=>value1,'cookieName2'=>'value2'......)//storing cookies and their values
- $userAgent=>userAgent,
- method =>HTTP method [GET/POSt]
- */
- function fetchPage( $url,$data ,$cookie='',$userAgent ='',$method = 'GET') //sends data array(param=>val,...) to the page $url in post method and returns the reply string
- {
- $httpArr = array();
- $header = "Accept-language: en\r\n";
- if($method != 'GET'){
- $method = 'POST';
- $data = http_build_query( $data );
- $header = $header."Content-Type: application/x-www-form-urlencoded\r\n" .
- "Content-Length: " . strlen( $data ).'\r\n';
- $content = $data;
- } else {
- $content = '';
- $queryArr = array();
- foreach($data as $key => $value) {
- array_push($queryArr,$key.'='.$value);
- }
- $url = $url.'?'.implode('&',$queryArr);
- }
- if($cookie != '') {
- $cookieStr = 'Cookie: ';
- $len = sizeof($cookie);
- $i = 0;
- foreach($cookie as $key => $val) {
- $cookieStr = $cookieStr.$key.'='.$val;
- $cookieStr = $i != $len - 1 ?$cookieStr.'; ':$cookieStr;
- $i++;
- }
- }
- $userAgent = $userAgent !='' ? $userAgent:'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)';
- $header = $header.'\r\n'.$userAgent.$cookie;
- $httpArr['method'] = $method;
- $httpArr['follow_location'] = true;
- $httpArr['header'] = $header;
- $context = stream_context_create( array(
- "http" => $httpArr
- ) );
- $page = file_get_contents( $url, false, $context );
- var_dump($http_response_header);
- return $page;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement