php if isset _GET form to isset _GET to int abs _GET to text htmlspeci

 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
<?php
if (isset($_GET['form']))
{
$to = (isset($_GET['to']) ? (int) abs($_GET['to']) : 0);
$text = htmlspecialchars($_POST['text']);
if (mb_strlen($text)<2 OR mb_strlen($text)>250)
{
$err ='Длина сообщения 2-250 символов';
}
if ($err)
{
$_SESSION['error'] = $err;
header("Location:?");
exit;
} else {
$msg = $db->query("INSERT INTO `guest` SET `user`=?,`to`=?,`time`=?,`text`=?",
array($user['id'],$to,time(),$text));
header("Location:/guest");
exit;
}
}
?>
<div class = "well"/>
<form action = "guest.php?form" method="post"/>
<input type ='text' name='text' placeholder='Введите сообщение' class='input-block-level'/>
<button class="btn btn-inverse" type="submit">Отправить</button>
</form>
</div>