PHP's file_get_contents () and cookies

December 6, 2006

Sending cookies - you can do it with file_get_contents () - just look at the stream functions’ constants (the context parameter). But I found out it’s much easier using the curl plugin (which isn’t always available, btw, but neither is file_get_contents ()):

$c = curl_init ($url);

curl_setopt ($c, CURLOPT_VERBOSE, 1); // For testing

curl_setopt ($c, CURLOPT_COOKIE, "variable=value");

curl_exec ($c);

It’s that simple. An awesome tool for creating all kinds of site parsers.