1--TEST-- 2local user streams must not be able to open() url's 3--INI-- 4allow_url_fopen=1 5allow_url_include=0 6--FILE-- 7<?php 8class test { 9 public $context; 10 private $data = '<?php echo "Hello World\n";?>'; 11 private $pos; 12 private $stream = null; 13 14 function stream_open($path, $mode, $options, &$opened_path) 15 { 16 if (strpos($path, "test2://") === 0) { 17 $this->stream = fopen("test1://".substr($path, 8), $mode); 18 return !empty($this->stream); 19 } 20 if (strchr($mode, 'a')) 21 $this->pos = strlen($this->data); 22 else 23 $this->pos = 0; 24 25 return true; 26 } 27 28 function stream_read($count) 29 { 30 if (!empty($this->stream)) { 31 return fread($this->stream, $count); 32 } 33 $ret = substr($this->data, $this->pos, $count); 34 $this->pos += strlen($ret); 35 return $ret; 36 } 37 38 function stream_tell() 39 { 40 if (!empty($this->stream)) { 41 return ftell($this->stream); 42 } 43 return $this->pos; 44 } 45 46 function stream_eof() 47 { 48 if (!empty($this->stream)) { 49 return feof($this->stream); 50 } 51 return $this->pos >= strlen($this->data); 52 } 53 54 function stream_seek($offset, $whence) 55 { 56 if (!empty($this->stream)) { 57 return fseek($this->stream, $offset, $whence); 58 } 59 switch($whence) { 60 case SEEK_SET: 61 if ($offset < $this->data && $offset >= 0) { 62 $this->pos = $offset; 63 return true; 64 } else { 65 return false; 66 } 67 break; 68 case SEEK_CUR: 69 if ($offset >= 0) { 70 $this->pos += $offset; 71 return true; 72 } else { 73 return false; 74 } 75 break; 76 case SEEK_END: 77 if (strlen($this->data) + $offset >= 0) { 78 $this->pos = strlen($this->data) + $offset; 79 return true; 80 } else { 81 return false; 82 } 83 break; 84 default: 85 return false; 86 } 87 } 88 89} 90 91stream_register_wrapper("test1", "test", STREAM_IS_URL); 92stream_register_wrapper("test2", "test"); 93echo @file_get_contents("test1://hello"),"\n"; 94@include "test1://hello"; 95echo @file_get_contents("test2://hello"),"\n"; 96include "test2://hello"; 97?> 98--EXPECTF-- 99<?php echo "Hello World\n";?> 100<?php echo "Hello World\n";?> 101 102Warning: fopen(): test1:// wrapper is disabled in the server configuration by allow_url_include=0 in %sinclude_userstream_002.php on line 11 103 104Warning: fopen(test1://hello): Failed to open stream: no suitable wrapper could be found in %sinclude_userstream_002.php on line 11 105 106Warning: include(test2://hello): Failed to open stream: "test::stream_open" call failed in %sinclude_userstream_002.php on line 90 107 108Warning: include(): Failed opening 'test2://hello' for inclusion (include_path='%s') in %sinclude_userstream_002.php on line 90 109