HTTP Get Request using PHP - URGENT!!!

Discussion in 'PHP' started by rushskeith, Jan 20, 2008.

  1. #1
    Dear All,

    im new to PHP and i have done my application end of this week. :eek:

    Can someone help me in how to do HTTP Get Request using PHP ..

    scenario :

    i have to send a HTTP Get Request to CPA (http://<CPA_URL>/login). There are 3 parameters.

    then... CPA will send to me some parameters embedded in response headers.

    Can anyone help .. how to capture the response headers using PHP...

    please help me ... :confused:
     
    rushskeith, Jan 20, 2008 IP
  2. ngcoders

    ngcoders Active Member

    Messages:
    206
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    55
    #2
    Search for snoopy php for fsock implementation

    Given below is a CURL one

    
    class CURL {
    	var $callback = false;
    	var $secure = false;
    	var $conn = false;
    	var $cookiefile =false;
    
    	
    	function CURL($u) {
    	  global $debug;
    		$this->conn = curl_init();
    		if ($debug) {
    			$this->cookiefile='f:/crawler/temp/'.md5($u);
    		} else {
    			$this->cookiefile='temp/'.md5($u);
    		}
    		
    	}
    
    	function setCallback($func_name) {
    		$this->callback = $func_name;
    	}
    
    	function close() {
    		curl_close($this->conn);
    		/*if (is_file($this->cookiefile)) {
    			unlink($this->cookiefile);
    		} */
    		
    	}
    	
    	
    	function doRequest($method, $url, $vars) {
    
    		$ch = $this->conn;
    
    		$user_agent = "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)";
    
    		curl_setopt($ch, CURLOPT_URL, $url);
    		curl_setopt($ch, CURLOPT_HEADER, 1);
    		curl_setopt($ch, CURLOPT_USERAGENT,$user_agent);
    
    		if($this->secure) {
    			curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,  0);
    			curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
    		}
    
    		curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    		curl_setopt($ch, CURLOPT_COOKIEJAR, $this->cookiefile);
            curl_setopt($ch, CURLOPT_COOKIEFILE, $this->cookiefile);
    
    		if ($method == 'POST') {
    			curl_setopt($ch, CURLOPT_POST, 1);
    			curl_setopt($ch, CURLOPT_POSTFIELDS, $vars);
    		}
    		$data = curl_exec($ch);
    		if ($data) {
    			if ($this->callback)
    			{
    				$callback = $this->callback;
    				$this->callback = false;
    				return call_user_func($callback, $data);
    			} else {
    				return $data;
    			}
    		} else {
    			return curl_error($ch);
    		}
    	}
    
    	function get($url) {
    		return $this->doRequest('GET', $url, 'NULL');
    	}
    
    	function post($url, $vars) {
    		return $this->doRequest('POST', $url, $vars);
    	}
    }
    
    
    PHP:
     
    ngcoders, Jan 20, 2008 IP