Tag Archives: Context

stream_context_create

Stream_context_create — Creates a stream context.

Creates and returns a stream context with any options supplied in options preset.

<?php
 $opts = array(
 'http'=>array(
 'method'=>"GET",
 'header'=>"Accept-language: en\r\n" .
 "Cookie: foo=bar\r\n"
 )
 );

$context = stream_context_create($opts);
 $fp = fopen('http://www.phpcodez.com', 'r', false, $context);
 fpassthru($fp);
 fclose($fp);
?>

REST Context Switching

o Refers to the act of providing different output based on criteria from the request

o The process inspects the http request headers and/or the request uri, and varies the response appropriately

o Commonly used for:

 providing different output for requests originated via xmlhttprequest

 providing different output based on accept http headers (ex: rest endpoints)

 providing alternate layouts/content based on browser detection