Skip to content

Instantly share code, notes, and snippets.

@kenjis
Created August 31, 2011 23:57
Show Gist options
  • Save kenjis/1185081 to your computer and use it in GitHub Desktop.
Save kenjis/1185081 to your computer and use it in GitHub Desktop.
CodeIgniter contoller which tests ip_address()
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Test_ip_address extends CI_Controller {
function __construct()
{
parent::__construct();
}
function index()
{
$uri = 'http://localhost/cir_test/index.php/ip_address';
// send X-FORWARDED-FOR
$opt = array(
'http'=> array(
'header' => 'X-FORWARDED-FOR: 88.88.88.88',
)
);
$context = stream_context_create($opt);
$page = file_get_contents($uri, 0, $context);
echo $page, "<br />\n";
// send CLIENT-IP
$opt = array(
'http'=> array(
'header' => 'CLIENT-IP: 99.99.99.99',
)
);
$context = stream_context_create($opt);
$page = file_get_contents($uri, 0, $context);
echo $page, "<br />\n";
// send X-FORWARDED-FOR and CLIENT-IP
$opt = array(
'http'=> array(
'header' => array('X-FORWARDED-FOR: 88.88.88.88',
'CLIENT-IP: 99.99.99.99',
)
)
);
$context = stream_context_create($opt);
$page = file_get_contents($uri, 0, $context);
echo $page, "<br />\n";
}
}
/* End of file test_ip_address.php */
/* Location: ./application/controllers/test_ip_address.php */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment