1
1
<?php
2
- if ( $ _SERVER ['REQUEST_METHOD ' ] == "POST " ) {
2
+ if ( $ _SERVER ['REQUEST_METHOD ' ] == "POST " ) {
3
3
4
- $ HOST = $ _SERVER ['REQUEST_SCHEME ' ].':// ' .$ _SERVER ['SERVER_ADDR ' ].'/ ' ;
4
+ $ HOST = "http:// " . $ _SERVER ['HTTP_HOST ' ];
5
+ $ HOST .= str_replace (basename ($ _SERVER ['SCRIPT_NAME ' ]), "" , $ _SERVER ['SCRIPT_NAME ' ]);
5
6
6
- if ( isset ($ _POST ['data ' ]) ) {
7
+ if ( isset ($ _POST ['data ' ])) {
7
8
8
9
$ PHP_FILE_PATH = 'code/index.php ' ;
9
10
10
11
$ CODE_DATA = '<?php
11
- '. $ _POST ['data ' ];
12
+ ' . $ _POST ['data ' ];
12
13
13
- //UPDATING FILE
14
- $ myFile = fopen ($ PHP_FILE_PATH , "w " ) or die ("Unable to open file! " );
15
- fwrite ($ myFile , $ CODE_DATA );
16
- fclose ($ myFile );
14
+ //UPDATING FILE
15
+ $ myFile = fopen ($ PHP_FILE_PATH , "w " ) or die ("Unable to open file! " );
16
+ fwrite ($ myFile , $ CODE_DATA );
17
+ fclose ($ myFile );
17
18
18
- $ URL = $ HOST . ' /writephp/ code/index.php ' ;
19
+ $ URL = $ HOST . ' code/index.php ' ;
19
20
20
- $ ch = curl_init ();
21
- curl_setopt ($ ch ,CURLOPT_URL , $ URL );
21
+ $ ch = curl_init ();
22
+ curl_setopt ($ ch , CURLOPT_URL , $ URL );
22
23
curl_setopt ($ ch , CURLOPT_RETURNTRANSFER , true );
23
24
curl_setopt ($ ch , CURLOPT_TIMEOUT , 20 );
24
25
curl_setopt ($ ch , CURLOPT_CONNECTTIMEOUT , 5 );
25
26
$ response = curl_exec ($ ch );
26
27
curl_close ($ ch );
27
28
28
- $ res = array ('status ' =>1 ,'msg ' =>'Success!!! ' ,'data ' =>$ response );
29
- } else $ res = array ('status ' =>0 ,'error ' =>'Invalid Parameters!!! ' );
30
- echo json_encode ($ res );exit ();
29
+ $ res = array ('status ' => 1 , 'msg ' => 'Success!!! ' , 'data ' => $ response );
30
+ } else $ res = array ('status ' => 0 , 'error ' => 'Invalid Parameters!!! ' );
31
+ echo json_encode ($ res );
32
+ exit ();
31
33
}
32
34
33
35
?>
34
36
35
37
36
38
<!DOCTYPE html>
37
39
<html>
40
+
38
41
<head>
39
42
<meta charset="utf-8">
40
43
<meta name="viewport" content="width=device-width, initial-scale=1">
45
48
<link rel="stylesheet" type="text/css" href="assets/css/style.css">
46
49
<!-- /CSS -->
47
50
</head>
51
+
48
52
<body>
49
- <input type="hidden" name="currentPageUrl" value="<?php echo $ HOST . '/writephp/ ' ; ?> ">
53
+ <input type="hidden" name="currentPageUrl" value="<?php echo $ HOST . '/writephp/ ' ; ?> ">
50
54
51
55
<section class="pt-5 pb-5">
52
56
<div class="container-fluid">
59
63
<div class="code-box">
60
64
<div class="mb-3">
61
65
<label class="text-danger"><strong><?php</strong></label>
62
- <div id="editor" name="data"></div>
66
+ <div id="editor" name="data"></div>
63
67
</div>
64
68
</div>
65
69
</div>
66
70
67
71
<div class="col-md-2 ps-md-0 pe-md-0">
68
72
<div class="btn-box-container">
69
73
<div class="text-center">
70
- <button class="btn btn-primary" type="button" id="formSubmitButton">Run Code</button>
74
+ <button class="btn btn-primary" type="button" id="formSubmitButton">Run Code</button>
71
75
</div>
72
76
</div>
73
77
</div>
92
96
<script type="text/javascript" src="assets/js/style.js"></script>
93
97
<!-- /SCRIPTS -->
94
98
</body>
99
+
95
100
</html>
0 commit comments