Link to home
Start Free TrialLog in
Avatar of ngocquynh85
ngocquynh85

asked on

header . socket and cookies

this is the function I found which to get header of URL.
But I don't know how to use IE-cookies in this.

function get_headers($url,$format=0)
   {
       $url_info=parse_url($url);
       $port = isset($url_info['port']) ? $url_info['port'] : 80;
       $fp=fsockopen($url_info['host'], $port, $errno, $errstr, 30);
       
       if($fp)
       {
           $head = "HEAD ".@$url_info['path']."?".@$url_info['query']." HTTP/1.0\r\nHost: ".@$url_info['host']."\r\n\r\n";            
           fputs($fp, $head);      
           while(!feof($fp))
           {
               if($header=trim(fgets($fp, 1024)))
               {
                   if($format == 1)
                   {
                       $key = array_shift(explode(':',$header));
                       // the first element is the http header type, such as HTTP 200 OK,
                       // it doesn't have a separate name, so we have to check for it.
                       if($key == $header)
                       {
                           $headers[] = $header;
                       }
                       else
                       {
                           $headers[$key]=substr($header,strlen($key)+2);
                       }
                       unset($key);
                   }
                   else
                   {
                       $headers[] = $header;
                   }
               }
           }
           return $headers;
       }
       else
       {
           return false;
       }
   }
Avatar of Roonaan
Roonaan
Flag of Netherlands image

"But I don't know how to use IE-cookies in this.".

To do what exactly?

-r-
Avatar of ngocquynh85
ngocquynh85

ASKER

uhm, I want to use cookie when I get header.
first, I login into a website (by IE),
then I use this function to get header of one page in this site.
But it didn't work as I wish, because this function don't include cookie when I login a website.
:|
ASKER CERTIFIED SOLUTION
Avatar of Roonaan
Roonaan
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial