0
Before I asked that question, I did a lot of research, but I couldn’t figure it out on my own. Well I’m new in PHP and also in 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 make this code work but I’ve tried everything and a Error:500 (I think it’s the incorrect code). I need two functions that I can’t implement, one is the function that if someone tries to save in my bots.txt file an empty text or spaces shows an error; the other is that my reset button doesn’t work.
I tested the restart function in a separate file and it worked, but while joining the error.
Example: Website
<?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>';
?>
Follow below the code well identado
<?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>';
?>
No problem if you give me sources where I can solve my problem, I search on my own if that’s the case, thank you in advance.
– Erick
This problem can be found more easily with the code well identado, gets the tip
– Costamilam
These paths "C:/Users/Administrator/Onedrive/.." will not work if your site is in a hosting. And depending on the server configuration it forwards directly to error 500, 404, and hides the errors of php, mysql, etc..
– Andrei Coelho
agree with @Andreicoelho because your site should not have permission to access the directory
– Marcos Brinner