-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathcreate.php
51 lines (27 loc) · 837 Bytes
/
create.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
<?php
$ch = require "init_curl.php";
curl_setopt($ch, CURLOPT_URL, "https://api.github.com/user/repos");
//curl_setopt($ch, CURLOPT_POST, true);
//curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($_POST));
$response = curl_exec($ch);
$status_code = curl_getinfo($ch, CURLINFO_RESPONSE_CODE);
curl_close($ch);
$data = json_decode($response, true);
if ($status_code === 422) {
echo "Invalid data: ";
print_r($data["errors"]);
exit;
}
if ($status_code !== 201) {
echo "Unexpected status code: $status_code";
var_dump($data);
exit;
}
?>
<?php require "header.html" ?>
<h1>New Repository</h1>
<p>Repository created successfully.
<a href="show.php?full_name=<?= $data["full_name"] ?>">Show</a>
</p>
<?php require "footer.html" ?>