-
Notifications
You must be signed in to change notification settings - Fork 0
/
testing.php
executable file
·45 lines (37 loc) · 1.02 KB
/
testing.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
<?php
/**
* Faster data transfer using file_get_contents
*/
function send_message_to_slack($message = '') {
$data = array(
'text' => $message
);
$postdata = json_encode($data);
$opts = array('http' =>
array(
'method' => 'POST',
'header' => 'Content-Type: application/x-www-form-urlencoded',
'content' => $postdata
)
);
$context = stream_context_create($opts);
$result = file_get_contents('https://hooks.slack.com/services/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', false, $context);
if($result) {
return true;
}
return false;
}
if(isset($_POST['send'])) {
if(!empty($_POST['text'])) {
if(send_message_to_slack($_POST['text'])) {
echo "Message sent";
} else {
echo "Something went wrong";
}
}
}
?>
<form action="<?php echo $_SERVER['REQUEST_URI']; ?>" method="post">
<input type="text" name="text">
<input type="submit" value="Send" name="send">
</form>