Before asking this question I researched a lot, but I could not solve it myself. I'm new to PHP and programming, I wanted to understand how the IF and ELSE operators work in PHP and also the GET and POST methods, what I need to do is to make this code work, but I tried everything and an error: 500 I believe it is by the wrong code). I need two functions that I can not implement, one is the function that if someone tries to save in my bots.txt file an empty text or spaces apprehensible an error; The other is that my restart button does not work.
I tested the restart function on a separate file and it worked, but when I joined the error.
Example: Site
<?php
if(!empty($_POST['text'])){
$fp = fopen("C:/Users/Administrator/OneDrive/COUP_Server4Edit/bots.txt" , "r");
$lines = '';
while(!feof($fp)){
$lines .= fgets($fp , 4096) ;
}
fclose($fp);
$re = fopen("C:/Users/Administrator/OneDrive/COUP_Server4Edit/bots.txt" , 'w');
$lines .= $_POST['text'];
$write = fwrite($re , $lines . PHP_EOL);
if(empty($write) OR !strstr($write,''))
{
echo "<script> alert('Não é permitido nomes em branco ou vazios!') </script>";
}
else if($write){
echo "<script> alert('Bot salvo com sucesso!') </script>";
}else if($write == false ){
echo "<script> alert('Ops.. ocorreu um erro inesperado :(')</script>";
}
}
if (!empty($_GET['rr'])) {
echo "<script> alert('Servidor reiniciado com sucesso!') </script>";
exec('wscript "C:/Users/Administrator/OneDrive/COUP_Server4Edit/A_Fechar_Servidor_Hidden.vbs"');
} else {
"<script> alert('Erro ao tentar reiniciar!') </script>";
}
echo '<form action="#" method="post">';
echo '<fieldset>';
echo '<legend>Erko Now | COUP - BR</legend>';
echo '<center>';
echo '<img src="img/coupbr.jpg" alt="Coup BR"><br>';
echo '<b>';
echo 'Nome do Bot:';
echo '</b>';
echo '<input type="text" name="text" rows="20" cols="50" placeholder="Nome" title="Digite o nome do bot que deseja adicionar">';
echo '<input type="submit" value="Salvar" title="Gravar informações">';
echo '<form action="#" method="get">';
echo '<input type="hidden" name="rr" value="run">';
echo '<input type="submit" value="Reiniciar">';
echo '</form>';
echo '</fieldset>';
echo '</center>';
echo '</form>';
?>
Below the well-defined code
<?php
if(!empty($_POST['text'])){
$fp = fopen("C:/Users/Administrator/OneDrive/COUP_Server4Edit/bots.txt" , "r");
$lines = '';
while(!feof($fp)){
$lines .= fgets($fp , 4096) ;
}
fclose($fp);
$re = fopen("C:/Users/Administrator/OneDrive/COUP_Server4Edit/bots.txt" , 'w');
$lines .= $_POST['text'];
$write = fwrite($re , $lines . PHP_EOL);
if(empty($write) OR !strstr($write,'')){
echo "<script> alert('Não é permitido nomes em branco ou vazios!') </script>";
}else if($write){
echo "<script> alert('Bot salvo com sucesso!') </script>";
}else if($write == false ){
echo "<script> alert('Ops.. ocorreu um erro inesperado :(')</script>";
}
}
if (!empty($_GET['rr'])) {
echo "<script> alert('Servidor reiniciado com sucesso!') </script>";
exec('wscript "C:/Users/Administrator/OneDrive/COUP_Server4Edit/A_Fechar_Servidor_Hidden.vbs"');
} else {
"<script> alert('Erro ao tentar reiniciar!') </script>";
}
echo '<form action="#" method="post">';
echo '<fieldset>';
echo '<legend>Erko Now | COUP - BR</legend>';
echo '<center>';
echo '<img src="img/coupbr.jpg" alt="Coup BR"><br>';
echo '<b>';
echo 'Nome do Bot:';
echo '</b>';
echo '<input type="text" name="text" rows="20" cols="50" placeholder="Nome" title="Digite o nome do bot que deseja adicionar">';
echo '<input type="submit" value="Salvar" title="Gravar informações">';
echo '<form action="#" method="get">';
echo '<input type="hidden" name="rr" value="run">';
echo '<input type="submit" value="Reiniciar">';
echo '</form>';
echo '</fieldset>';
echo '</center>';
echo '</form>';
?>