PHP WebSocket2 Library
PHP5 Library for browsing web
Main Page
Data Structures
Examples
redirection_interception.php
This is an example of how to intercept automatic HTTP redirections with
HttpRequestManager
.
<?php
require
'../websock2.php'
;
define(
'EOL'
, php_sapi_name() ===
'cli'
? PHP_EOL :
'<br>'
);
//Create HTTP request manager and supply it with socket
$manager =
new
HttpRequestManager
(
new
FileSocket
);
//Set up redirection interception
$manager->setOnRedirectCallback(
function
(
WebRequest
$original_request,
WebResponse
$response,
WebRequest
$new_request, $http_code,
HttpRequestManager
$manager)
{
echo
'We are redirected to: '
. $new_request->
getFullAddress
() . EOL;
return
true
;
//Return false to abort redirect and return from runRequest
});
//This request will redirect us 6 times
echo $manager->
runRequest
(
WebRequest::createFromUrl
(
'http://httpbin.org/redirect/6'
))->getBody();
Generated on Sun Jan 25 2015 20:05:38 for PHP WebSocket2 Library by
1.8.9.1