class Net

This general purpose library for HTTP communications.

This class attempts to solve the problem that lots of PHP environments have different approaches to doing GET and POST requests. Some use CURL and others use context streams. This code tries one way or another to figure out the best way to handle these and make these calls work using whatever library code that is available.

The best way for things work is for CURL to be avaialable. If CURL is available, it is used for everything and forks well.

Properties

static $VERIFY_PEER

Methods

static 
getLastGETURL()

No description

static 
getLastGETImpl()

No description

static 
getLastHeadersSent()

No description

static 
getLastHttpResponse()

No description

static 
getLastCurlError()

No description

static 
getLastHeadersReceived()

No description

static 
getLastBODYURL()

No description

static 
getLastBODYMethod()

No description

static 
getLastBODYImpl()

No description

static 
getLastBODYContent()

No description

static 
getLastBODYDebug()

No description

static 
parseHeaders($headerstr = false)

Extract a set of header lines into an array

static 
doGet($url, $header = false)

No description

static 
getStream($url, $header = false)

No description

static 
getCurl($url, $header = false)

No description

static 
getBodySentDebug()

No description

static 
getBodyReceivedDebug()

No description

static 
getGetSentDebug()

No description

static 
getGetReceivedDebug()

No description

static 
doBody($url, $method, $body, $header)

No description

static 
bodySocket($endpoint, $method, $data, $moreheaders = false)

No description

static 
bodyStream($url, $method, $body, $header)

No description

static 
bodyCurl($url, $method, $body, $header)

No description

static 
send403($msg = null, $detail = null)

Send a 403 header

static 
send400($msg = 'Malformed request', $detail = null)

Send a 400 (Malformed request) header

static string
getIP()

Get the actual IP address of the incoming request.

static 
serverIP()

No description

static 
isRoutable($ipaddr)

No description

static 
httpSuccess($httpcode)

Return true if the http code is 2xx (success)

static 
setCookieStrong($name, $value, $domain, $expires)

Put as much oomph into setting a cookie as we can

Details

at line 30
static getLastGETURL()

at line 34
static getLastGETImpl()

at line 38
static getLastHeadersSent()

at line 42
static getLastHttpResponse()

at line 46
static getLastCurlError()

at line 50
static getLastHeadersReceived()

at line 54
static getLastBODYURL()

at line 58
static getLastBODYMethod()

at line 62
static getLastBODYImpl()

at line 66
static getLastBODYContent()

at line 71
static getLastBODYDebug()

at line 96
static parseHeaders($headerstr = false)

Extract a set of header lines into an array

Takes a newline separated header sting and returns a key/value array

Parameters

$headerstr

at line 112
static doGet($url, $header = false)

Parameters

$url
$header

at line 139
static getStream($url, $header = false)

Parameters

$url
$header

at line 155
static getCurl($url, $header = false)

Parameters

$url
$header

at line 202
static getBodySentDebug()

at line 214
static getBodyReceivedDebug()

at line 230
static getGetSentDebug()

at line 241
static getGetReceivedDebug()

at line 260
static doBody($url, $method, $body, $header)

Parameters

$url
$method
$body
$header

at line 296
static bodySocket($endpoint, $method, $data, $moreheaders = false)

Parameters

$endpoint
$method
$data
$moreheaders

at line 352
static bodyStream($url, $method, $body, $header)

Parameters

$url
$method
$body
$header

at line 370
static bodyCurl($url, $method, $body, $header)

Parameters

$url
$method
$body
$header

at line 438
static send403($msg = null, $detail = null)

Send a 403 header

Parameters

$msg
$detail

at line 454
static send400($msg = 'Malformed request', $detail = null)

Send a 400 (Malformed request) header

Parameters

$msg
$detail

at line 477
static string getIP()

Get the actual IP address of the incoming request.

Handle being behind a load balancer or a proxy like Cloudflare. This will often return NULL when talking to localhost to make sure to test code using this on a real IP address.

Adapted from: https://www.chriswiegman.com/2014/05/getting-correct-ip-address-php/ With some additional explode goodness via: http://stackoverflow.com/a/25193833/1994792

Return Value

string The IP address of the incoming request or NULL if it cannot be determined.

at line 539
static serverIP()

at line 547
static isRoutable($ipaddr)

Parameters

$ipaddr

at line 558
static httpSuccess($httpcode)

Return true if the http code is 2xx (success)

Parameters

$httpcode

at line 565
static setCookieStrong($name, $value, $domain, $expires)

Put as much oomph into setting a cookie as we can

Parameters

$name
$value
$domain
$expires