1--TEST-- 2ldap_get_option() and ldap_set_option() tests related to ldap controls 3--CREDITS-- 4Côme Chilliet <mcmic@php.net> 5--SKIPIF-- 6<?php 7require_once('skipif.inc'); 8require_once('skipifbindfailure.inc'); 9?> 10--FILE-- 11<?php 12include "connect.inc"; 13 14$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version); 15insert_dummy_data($link, $base); 16 17function build_ctrl_paged_value($int, $cookie) 18{ 19 // This is basic and will only work for small values 20 $hex = ''; 21 if (!empty($int)) { 22 $str = sprintf("%'.02x", $int); 23 $hex .= '02'.sprintf("%'.02x%s", strlen($str)/2, $str); 24 } 25 $hex .= '04'.sprintf("%'.02x", strlen($cookie)).bin2hex($cookie); 26 return hex2bin('30'.sprintf("%'.02x", strlen($hex)/2).$hex); 27} 28 29$controls_set = array( 30 array( 31 'oid' => LDAP_CONTROL_PAGEDRESULTS, 32 'iscritical' => TRUE, 33 'value' => build_ctrl_paged_value(1, 'opaque') 34 ) 35); 36$controls_set2 = array( 37 array( 38 'oid' => LDAP_CONTROL_PAGEDRESULTS, 39 'iscritical' => TRUE, 40 'value' => array( 41 'size' => 1, 42 'cookie' => '', 43 ) 44 ) 45); 46var_dump( 47 bin2hex($controls_set[0]['value']), 48 ldap_get_option($link, LDAP_OPT_SERVER_CONTROLS, $controls_get), 49 ldap_set_option($link, LDAP_OPT_SERVER_CONTROLS, $controls_set), 50 ldap_get_option($link, LDAP_OPT_SERVER_CONTROLS, $controls_get), 51 $controls_get, 52 ldap_set_option($link, LDAP_OPT_SERVER_CONTROLS, $controls_set2), 53 ldap_get_option($link, LDAP_OPT_SERVER_CONTROLS, $controls_get), 54 $controls_get, 55 $result = ldap_search($link, $base, "(objectClass=person)", array('cn')), 56 ldap_get_entries($link, $result)['count'], 57 ldap_set_option($link, LDAP_OPT_SERVER_CONTROLS, array()), 58 ldap_get_option($link, LDAP_OPT_SERVER_CONTROLS, $controls_get) 59); 60?> 61===DONE=== 62--CLEAN-- 63<?php 64include "connect.inc"; 65 66$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version); 67remove_dummy_data($link, $base); 68?> 69--EXPECTF-- 70string(26) "300b02010104066f7061717565" 71bool(false) 72bool(true) 73bool(true) 74array(1) { 75 ["1.2.840.113556.1.4.319"]=> 76 array(3) { 77 ["oid"]=> 78 string(22) "1.2.840.113556.1.4.319" 79 ["iscritical"]=> 80 bool(true) 81 ["value"]=> 82 array(2) { 83 ["size"]=> 84 int(1) 85 ["cookie"]=> 86 string(6) "opaque" 87 } 88 } 89} 90bool(true) 91bool(true) 92array(1) { 93 ["1.2.840.113556.1.4.319"]=> 94 array(3) { 95 ["oid"]=> 96 string(22) "1.2.840.113556.1.4.319" 97 ["iscritical"]=> 98 bool(true) 99 ["value"]=> 100 array(2) { 101 ["size"]=> 102 int(1) 103 ["cookie"]=> 104 string(0) "" 105 } 106 } 107} 108resource(%d) of type (ldap result) 109int(1) 110bool(true) 111bool(false) 112===DONE=== 113