11.5 Sending Cookies with Your Request


You want to send an HTTP cookie to a remote server when performing a transaction.

Technique

Set the cookies property of the Net_Curl PEAR class:

 <?php // Initialize $conn = new Net_Curl('http://www.zend.com/'); if (Net_Curl::isError($conn)) {     die(sprintf('Error [%d]: %s',                 $conn->getCode(), $conn->getMessage())); } // Set transfer options $conn->cookies = array(name  => 'Sterling',                        email => 'sterling@php.net'); // Execute transfer $data = $conn->execute(); if (Net_Curl::isError($data)) {     die(sprintf('Error [%d]: %s',                 $data->getCode(), $data->getMessage())); } print "The results of your transfer were: \n<br>\n"; print $data; ?> 

Comments

When setting the cookies property of the Net_Curl class, you can provide an array of key/value pairs; a file containing the cookie data in Netscape format or regular HTTP; colon -delimited data; or the raw cookie data itself (in Netscape or HTTP format).



PHP Developer's Cookbook
PHP Developers Cookbook (2nd Edition)
ISBN: 0672323257
EAN: 2147483647
Year: 2000
Pages: 351

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net