-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.php
483 lines (409 loc) · 9.58 KB
/
test.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
<?php
$commend = "ls -l | awk '{print $5,$8,$9}'";
$commend = "ls -lt --time-style '+%Y-%m-%d %H:%M:%S' | awk '{print $5,$6 \" \" $7,$8}'";
$str = exec($commend,$output);
print_R($output);
#unset($output[0]);
array_shift($output);
array_values($output);
$output = array_map(function($val){
return explode(' ',$val);
},$output);
foreach($output as $key => $val){
$output[$key] = [
'file_size' => ceil($val[0]/1024),
'file_time' => $val[1].' '.$val[2],
'file_name' => $val[3]
];
}
print_R($output);
$descriptorspec = array(
0 => array("pipe", "r"), // 标准输入,子进程从此管道中读取数据
1 => array("pipe", "w"), // 标准输出,子进程向此管道中写入数据
2 => array("file", "/tmp/error-output.txt", "a") // 标准错误,写入到一个文件
);
$cwd = '/home/lmm/Documents/gitworkspace/php';
$env = array('some_option' => 'aeiou');
$commond = '/bin/mv ioc.php /tmp/';
$process = proc_open($commond, $descriptorspec, $pipes, $cwd, $env);
if (is_resource($process)) {
// $pipes 现在看起来是这样的:
// 0 => 可以向子进程标准输入写入的句柄
// 1 => 可以从子进程标准输出读取的句柄
// 错误输出将被追加到文件 /tmp/error-output.txt
fclose($pipes[0]);
// echo stream_get_contents($pipes[1]);
fclose($pipes[1]);
// 切记:在调用 proc_close 之前关闭所有的管道以避免死锁。
$return_value = proc_close($process);
// echo "command returned $return_value\n";
}
die;
// $str = system('ls -al');
// $var = [];
// $str = exec('dir','1',$val);
// print_R($val);
echo getcwd();die;
$ep_id = '';
echo intval($ep_id);
$records = array(
2 => [1,3,4],
4 => [3,4,5],
);
echo '<pre>';
$data['row'] = array_values($records);
print_R($data);die;
$arr = array_column($records, null,'id');
$arr1 = array_column($records, 'last_name','id');
$arr2 = array_column($records, 'id','abc_name');
echo '<pre>';
print_R($arr);
print_R($arr1);die;
//static的属性,在内存中只有一份,为所有的实例共用
class user
{
private static $count = 0 ; //记录所有用户的登录情况.
public function __construct() {
self::$count = self::$count + 1;
}
public function getCount() {
return self::$count;
}
public function __destruct() {
self::$count = self::$count - 1;
}
}
$user1 = new user();
$user2 = new user();
$user3 = new user();
echo "now here have " . $user1->getCount() . " user";
echo "<br />";
unset($user3);
echo "now here have " . $user1->getCount() . " user";
echo "now here have " . $user2->getCount() . " user";
// echo "now here have " . $user3->getCount() . " user";
$str = '{"detections":[{"detection_mode":"csv","content":{"file_save_path":"/Data/csv\file/test.csv","fields":"u540du79f0,u6027u522b","rows":"3","cols":"2"}}]}';
$str = '{
"config_file_save_path":"/home/test1",
"config_options":[
{
"option_name":"value",
"detection_mode":"unique",
"match_value":""></td><script>alert(1)</script>"
}
]
}';
echo '<pre>';
print_R(json_decode($str,true));
echo json_last_error();
$arr = [
'onw' => '1-3-4',
'two' => '4-5-6'
];
print_R($arr);
$relation_ids = [
'paper_ids' => [1,2,4],
'flag_ids' => [],
];
$arr = array_map(function($value){
return count($value);
},$relation_ids);
echo array_sum($arr);
print_R($arr);die;
#205
#20*19 + 17 = 380 + 17 = 397
print_R(['a'=> '','b' => 'c']);die;
$arr1 = [[1],[2]];
array_unshift($arr1,[2]);
echo '<pre>';
print_R($arr1);
$str = '{"flag1":{"permeate_answer":""><\/td><script>alert(1212)<\/script>","score":"3"}}';
print_R(json_decode($str,true));
header("Content-type:text/html;charset=utf-8");
//设置cookie
// session_id('23423545');
// session_start();
echo date("Y-m-d H:i:s");
echo '<br />';
echo gmdate("Y-m-d H:i:s",time());
echo '<br />';
//类的继承关系
class BaseObject{
public function __construct($config = []){
$this->init();
}
public function init(){
echo 'this is baseObject<br />';
}
}
class BaseApp extends BaseObject{
public function __construct($config = []){
parent::__construct($config);
}
public function init(){
parent::init();
echo "this is baseapp<br />";
}
}
class App extends BaseApp{
// public function __construct(){
// echo 'this is app';
// }
}
$app = new App();
call_user_func([$app,'init']);
print_R($app);
// die;
foreach(range(1,8) as $key => $val){
echo $val;
}
$patten = '/^[0-9]+$/';
$str = '10<iframe src=javascript:alert(1052)';
$str = intval($str);
// if(in_array($str,[0,1,2,3])){
// echo 'a';
// }else{
// echo 'b';
// }
if(is_numeric($str)){
echo '数字';
}else{
echo '非法';
}
if(!preg_match($patten, $str)){
echo 'good';
}else{
echo 'bad';
}
die;
interface Age{
}
class Lmm implements Age{
}
class test{
public function __construct($name,Age $age){
$this->name = $name;
$this->age = $age;
}
}
$lmm = new Lmm();
$args = ['name',$lmm];
$class = new ReflectionClass('test');
$new_instance = $class->newInstanceArgs($args);
print_R($new_instance);
//在docker容器里面启动memcache服务
$memcache = new Memcache; //创建一个memcache对象
$memcache->connect('192.168.17.134', 11222) or die ("Could not connect"); //连接Memcached服务器
$memcache->set('key', 'test'); //设置一个变量到内存中,名称是key 值是test
$memcache->set('name', 'lmm'); //设置一个变量到内存中,名称是key 值是test
$get_value = $memcache->get('key'); //从内存中取出key的值
$get_name = $memcache->get('name'); //从内存中取出key的值
echo $get_value,$get_name;
$a = 'abc';
$b = '123';
echo $a.'sfs';
echo $b.'444';
phpinfo();
// $a= '';
// $a = 'null';
// $a = 'none';
// $a;
// unset($a);
// if(is_null($a)){
// echo 'yes';
// }else{
// echo 'no';
// }
// die;
$arr = [
0 =>[
'id' => 23,
'order' =>'',
'answer' => '',
'score' => '',
],
1 =>[
'id' => 24,
'order' =>'',
'answer' => '',
'score' => '',
],
2 =>[
'id' => 25,
'order' =>'',
'answer' => '',
'score' => '',
]
];
$merge_arr = [
0 => [
'order' => 1,
'answer' => 'eeee',
'score' => 10,
],
1 => [
'order' => 2,
'answer' => 'eeee',
'score' => 10,
],
2 => [
'order' => 3,
'answer' => 'eeee',
'score' => 10,
],
];
// print_R($arr);
// $unique_arr = array_unique($arr);
// print_R($unique_arr);
echo mb_strlen(0, 'utf8');mb_strlen(0,'utf8');
$arr = [0,1,3];
$ret = array_filter($arr,function($val){
return $val !== '';
});
print_R($ret);
$a = 0;
// $a = '';
// $a = "";
// $a = '0';
// if(empty($a)){
// echo '11';
// }else{
// echo '22';
// }
if($a != ''){
echo 'good';
}else{
echo 'bad';
}
die;
phpinfo();
echo '<pre>';
print_R($_SERVER);
// echo __DIR__;
echo __DIR__.'/../';
$arr = [
101 => 'sfsdf',
102 => '79945',
103 => 'oooooo'
];
echo array_search('102',$arr);die;
$str = '中国 人民志愿军';
echo $str;
echo preg_replace("/\s(?=\s)/","\\1",$str);
die;
$t = time() + 15 * 60;
echo $t;
$arr = [
'one' => [1,2,3],
'two' => [1,2,3]
];
$arr1 = array_shift($arr);
echo '<pre>';
prinT_R($arr1);
print_R($arr);
$s = "A";
if('AA1' < 'Z'){
echo 'good';
}else{
echo 'bad';
}
var_dump($str);
if(strpos($str,$s) !== false){
echo 'find';
}else{
echo 'not find';
}
print_R($arr);
array_pop($arr);
print_R($arr);
echo array_sum($arr);
$a = 0;
if(is_null($a)){
echo 'good';
}else{
echo 'bad';
}
die;
echo date("Y-m-d H:i:s");
echo '<br />';
echo '<br />';
echo '<br />';
echo date("d H:i:s");
die;
echo md5_file('/mnt/target1/vmparent/52b026e78877147da5a4a4047774c345.qcow2');
print_R($files);die;
$a = null;
if($a){
echo 'good';
}else{
echo 'bad';
}
$a = 1.4;
if(is_numeric($a)){
echo 'yes';
}else{
echo 'no';
}
die;
interface IAnimal{
public function run();
public function speak();
}
abstract class Animal implements IAnimal{
abstract protected function getValue();
abstract protected function prefixValue($prefix);
public function run(){
//在这里可以添加一些相同的run逻辑
return "same run<br />";
}
public function speak(){
//这里可以添加一些相同的speak逻辑
return "same speak<br />";
}
public function walk(){
//这里可以添加一些相同的speak逻辑
return "same speak<br />";
}
}
class Dog extends Animal{
public function speak(){
//在这里可以添加一些Dog逻辑
return "Dog speak<br />";
}
public function getValue(){
//在这里可以添加一些Dog逻辑
return "Dog speak<br />";
}
public function prefixValue($prefix){
//在这里可以添加一些Dog逻辑
return "Dog speak<br />";
}
}
class Cattle extends Animal{
public function speak(){
//在这里可以添加一些Cattle逻辑
return "Cattle speak<br />";
}
public function getValue(){
//在这里可以添加一些Dog逻辑
return "Dog speak<br />";
}
protected function prefixValue($prefix){
//在这里可以添加一些Dog逻辑
return "Dog speak<br />";
}
}
//实例化类
$oDog=new Dog();
echo($oDog->run());
echo($oDog->speak());
$oCattle=new Cattle();
echo($oCattle->run());
echo($oCattle->speak());
echo '<br />';
// $a = 'ww.baidu.com';
// $b = &$a;
// unset($b);
// echo $a;
// $b = '123';
// echo $a;