Skip to content

Commit 5595d4d

Browse files
committed
update changes for url
1 parent b6e10a0 commit 5595d4d

File tree

2 files changed

+25
-20
lines changed

2 files changed

+25
-20
lines changed

code/index.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?php
2-
$table = 5;
3-
for($i = 1; $i <= 10; $i++) {
4-
echo $table.' x '.$i.' = '.($table*$i).'<br>';
2+
$table = 5;
3+
for($i = 1; $i <= 10; $i++) {
4+
echo $table.' x '.$i.' = '.($table*$i).'<br>';
55
}

index.php

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,43 @@
11
<?php
2-
if( $_SERVER['REQUEST_METHOD'] == "POST" ) {
2+
if ($_SERVER['REQUEST_METHOD'] == "POST") {
33

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']);
56

6-
if( isset($_POST['data']) ){
7+
if (isset($_POST['data'])) {
78

89
$PHP_FILE_PATH = 'code/index.php';
910

1011
$CODE_DATA = '<?php
11-
'.$_POST['data'];
12+
' . $_POST['data'];
1213

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);
1718

18-
$URL = $HOST.'/writephp/code/index.php';
19+
$URL = $HOST . 'code/index.php';
1920

20-
$ch = curl_init();
21-
curl_setopt($ch,CURLOPT_URL, $URL);
21+
$ch = curl_init();
22+
curl_setopt($ch, CURLOPT_URL, $URL);
2223
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
2324
curl_setopt($ch, CURLOPT_TIMEOUT, 20);
2425
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
2526
$response = curl_exec($ch);
2627
curl_close($ch);
2728

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();
3133
}
3234

3335
?>
3436

3537

3638
<!DOCTYPE html>
3739
<html>
40+
3841
<head>
3942
<meta charset="utf-8">
4043
<meta name="viewport" content="width=device-width, initial-scale=1">
@@ -45,8 +48,9 @@
4548
<link rel="stylesheet" type="text/css" href="assets/css/style.css">
4649
<!-- /CSS -->
4750
</head>
51+
4852
<body>
49-
<input type="hidden" name="currentPageUrl" value="<?php echo $HOST.'/writephp/'; ?>">
53+
<input type="hidden" name="currentPageUrl" value="<?php echo $HOST . '/writephp/'; ?>">
5054

5155
<section class="pt-5 pb-5">
5256
<div class="container-fluid">
@@ -59,15 +63,15 @@
5963
<div class="code-box">
6064
<div class="mb-3">
6165
<label class="text-danger"><strong>&lt;?php</strong></label>
62-
<div id="editor" name="data"></div>
66+
<div id="editor" name="data"></div>
6367
</div>
6468
</div>
6569
</div>
6670

6771
<div class="col-md-2 ps-md-0 pe-md-0">
6872
<div class="btn-box-container">
6973
<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>
7175
</div>
7276
</div>
7377
</div>
@@ -92,4 +96,5 @@
9296
<script type="text/javascript" src="assets/js/style.js"></script>
9397
<!-- /SCRIPTS -->
9498
</body>
99+
95100
</html>

0 commit comments

Comments
 (0)