Oi pessoal.
Estou precisando gerar um aquivo de log em txt usando php, é possivel? Se tiver como alguém me enviar um exemplo, fico muito agradecido.
Peguei esse exemplo no forum, mas não consegui fazer nada com ele.
function Gera_Arquivos($nome_arquivo, $conteudo_arquivo) {
$handle = fopen ("$nome_arquivo", "w+");
$conteudo = $conteudo_arquivo;
fwrite($handle, $conteudo);
}
Abraço.
- Fórum WMO
- → Viewing Profile: Tópicos: colombo
Community Stats
- Group Usuários
- Active Posts 9
- Profile Views 986
- Member Title Novato no fórum
- Age Age Unknown
- Birthday Birthday Unknown
-
Sexo
Male
-
Localidade
Taboão da Serra
Topics I've Started
Funcao Gera Arquivo Txt
28/10/2010, 14:45
Ping Em Ip
18/10/2010, 15:02
Oi pessoal.
Desenvolvi um pequeno código para monitorar links de internet em minha empresa em PHP. O mesmo está funcionando corretamente, porém ele está enviando emails separadamente para cada ping no IP quando Offline. O problema que não estou conseguindo concatenar para enviar todos num somente email quando um deles tiver OFF. Olha o codigo:
<?php
echo ("<META HTTP-EQUIV='Refresh' CONTENT='300'>");
$data = date("d/m/y");
$hora = date("H:i");
echo ("DATA: $data ");
echo ("HORA: $hora <br>");
$pcs = array(
"LINK UNITELCO OSASCO" => "189.8.52.66",
"LINK UNITELCO TABOÃO" => "200.150.228.10",
"LINK SPEEDY OSASCO" => "192.168.0.250", /* "200.171.16.157" */
"LINK SPEEDY TABOÃO" => "200.168.142.132"
);
foreach ($pcs as $pc => $ip) { //construtor percorre o array do inicio ao fim
$ping = `ping $ip -n 1 -l 1`; // verifica se o computador respondeu
if (eregi("bytes=", $ping)) {
echo $pc . ": ONLINE" . "<br>";
} else {
echo $pc . ": OFFLINE" . "<br>";
envia_email("LINK DE INTERNET OFFLINE",$pc); //envia email automaticamente quando offline
}
}
// Função Disparar E-mail
.
.
.
?>
Se tiver como alguem me ajudar, agradeço.
Abraço.
Desenvolvi um pequeno código para monitorar links de internet em minha empresa em PHP. O mesmo está funcionando corretamente, porém ele está enviando emails separadamente para cada ping no IP quando Offline. O problema que não estou conseguindo concatenar para enviar todos num somente email quando um deles tiver OFF. Olha o codigo:
<?php
echo ("<META HTTP-EQUIV='Refresh' CONTENT='300'>");
$data = date("d/m/y");
$hora = date("H:i");
echo ("DATA: $data ");
echo ("HORA: $hora <br>");
$pcs = array(
"LINK UNITELCO OSASCO" => "189.8.52.66",
"LINK UNITELCO TABOÃO" => "200.150.228.10",
"LINK SPEEDY OSASCO" => "192.168.0.250", /* "200.171.16.157" */
"LINK SPEEDY TABOÃO" => "200.168.142.132"
);
foreach ($pcs as $pc => $ip) { //construtor percorre o array do inicio ao fim
$ping = `ping $ip -n 1 -l 1`; // verifica se o computador respondeu
if (eregi("bytes=", $ping)) {
echo $pc . ": ONLINE" . "<br>";
} else {
echo $pc . ": OFFLINE" . "<br>";
envia_email("LINK DE INTERNET OFFLINE",$pc); //envia email automaticamente quando offline
}
}
// Função Disparar E-mail
.
.
.
?>
Se tiver como alguem me ajudar, agradeço.
Abraço.
Chat Pronto Em Php
26/07/2010, 10:11
Oi pessoal.
Estou tentando fazer um chat...
Peguei esse codigo pronto de um colega, porém o mesmo está dando um erro de como se algum fecha-chave não tivesse sido colocado. Mas já cansei de verificar e parece ter todos.
Tem como alguem me ajudar, abraços.
Consegui resolver uma parte desse problema, porém agora está ocorrendo o seguinte erro:
Parse error: syntax error, unexpected $end in C:\xampp\htdocs\chat\index.php on line 370
Alguém pode me ajudar? abraço!
Estou tentando fazer um chat...
Peguei esse codigo pronto de um colega, porém o mesmo está dando um erro de como se algum fecha-chave não tivesse sido colocado. Mas já cansei de verificar e parece ter todos.
Tem como alguem me ajudar, abraços.
<? (empty($action)) ShowLoginForm(); elseif ($action == "posts") ShowAddPosts(); elseif ($action == "users") showusers(); elseif ($action == "form") GetInput(); elseif ($action == "logo") showlogo(); elseif ($action == "enter") Login(); function ShowLoginForm() { $time = date ("h:i A"); ?> <b>Entre Com Seu Nick/Nome</b> <form name="chat" method="post" action="index.php" target="_top"> <input type="text" name="nick" size="8" MAXLENGTH=9> <input type="hidden" name="action" value="enter"> <input type="hidden" name="chat" value="Entrou no Chat as <?php echo $time; ?>"> <input type="submit" name="Submit" value="Entrar"> <script language="JavaScript"> document.chat.nick.focus(); </script> </form> <?php } function Login() { global $HTTP_SESSION_VARS; global $chat; global $nick; session_start(); session_register("nick", $nick); if ($skin=="") { setCookie ("skin","yellow.css", time()+30240000);} ?> <frameset rows="*,70" cols="*,115" > <frame name="posts" src="index.php?action=posts&nick=<?php echo $nick; ?>&chat=<?php echo $chat; ?>" scrolling="auto" noresize frameborder="0" border="0"> <frame name="user" src="index.php?action=users" scrolling="no" noresize" frameborder="0" border="0" > <frame name="form" src="index.php?action=form&nick=<?php echo $nick; ?>" scrolling="no" noresize" frameborder="0" border="0" > <frame name="logo" src="index.php?action=logo" scrolling="no" noresize" frameborder="0" border="0" > </frameset> <noframes> <body> <p>This page uses frames, but your browser doesn't support them.</p> </body> </noframes> </frameset> <?php } function GetInput() { global $HTTP_SESSION_VARS; global $chat; global $nick; global $skin; $skin = $_COOKIE["skin"]; // Recommended but requires PHP 4.1 $activedir = "./style/"; @chdir($activedir); if ($skin=="") { print '<link rel="stylesheet" href="./style/yellow.css" type="text/css">';} else { ?> <link rel="stylesheet" href="<? echo $activedir.$skin; ?>" type="text/css"><? } ?> <body topmargin="0" leftmargin="0" marginwidth="0" marginheight="0"> <form onSubmit="return doSubmit" name="chatform" method="post" action="index.php" target="posts" > <table border="0" cellpadding="1" > <tr> <td valign="top" class="avatars"> <a href onClick="sendFace(1)"><img src="./img/smile.gif"</a> <a href onClick="sendFace(2)"><img src="./img/frown.gif"</a> <a href onClick="sendFace(3)"><img src="./img/bigsmile.gif"</a> <a href onClick="sendFace(4)"><img src="./img/angry.gif"</a> <a href onClick="sendFace(5)"><img src="./img/cool.gif"</a> <a href onClick="sendFace(6)"><img src="./img/tongue.gif"</a> <a href onClick="sendFace(7)"><img src="./img/huh.gif"</a> <a href onClick="sendFace(8)"><img src="./img/rolleyes.gif"</a> <a href onClick="sendFace(9)"><img src="./img/embarassed.gif"</a> <a href onClick="sendFace(10)"><img src="./img/lipsrsealed.gif"</a> <a href onClick="sendFace(11)"><img src="./img/kiss.gif"</a> <a href onClick="sendFace(12)"><img src="./img/cry.gif"</a> <a href onClick="sendFace(13)"><img src="./img/undecided.gif"</a> <a href onClick="sendFace(14)"><img src="./img/wink.gif"</a> </td><td valign="top" > <select name="skin" style="font: 9.9px verdana; color: #000000; width=80px;" onChange="makecookie();"> <option>Selecionar Tema</option> <? $handle=opendir('.'); while ($file = readdir($handle)) { if(is_file($file)) { $filelist[] = $file; } } closedir($handle); asort($filelist); while (list ($key, $file) = each($filelist)) { ereg(".gif | .jpg",$file); if ($file != "." && $file != ".." && (!is_dir($file))) { echo "<option value=\"".$file."\">".$file."</option>"; } } echo '</select>'; ?> </td></tr> <tr> <td valign="top"> <input type="text" name="chat" size="35" MAXLENGTH=200 onkeypress="if (event.keyCode==13) setTimeout('document.chatform.chat.value=\'\'',20);"> <input type="hidden" name="nick" value="<?php echo $nick; ?>"> <a href="javascript:void(doSubmit())" onMouseover="document.images['send'].src='./img/send2.gif'" onMouseout ="document.images['send'].src='./img/send1.gif'"> <img src="./img/send1.gif" name="send" border=0 align="top"></a> </td> </tr></td> <input type="hidden" name="action" value="posts"> <script language="JavaScript"> document.chatform.chat.focus(); </script> </form> </table> <script language="JavaScript"> function makecookie() { var expireDate = new Date expireDate.setMonth(expireDate.getMonth()+6) document.cookie = "skin=" + document.chatform.skin.value + "; expires=" + expireDate.toGMTString() parent.frames[1].document.location='index.php?action=users' parent.frames[3].document.location='index.php?action=logo' parent.frames[0].document.location='index.php?action=posts' parent.frames[2].document.location='index.php?action=form&nick=<?php echo $nick; ?>' document.chatform.chat.focus(); } function sendFace(faceNum) { switch(faceNum) { case 1: document.chatform.chat.value = document.chatform.chat.value + ' <img src='http://forum.wmonline.com.br/public/style_emoticons/default/smile.gif' class='bbc_emoticon' alt=':)' /> '; break; case 2: document.chatform.chat.value = document.chatform.chat.value + ' <img src='http://forum.wmonline.com.br/public/style_emoticons/default/sad.gif' class='bbc_emoticon' alt=':(' /> '; break; case 3: document.chatform.chat.value = document.chatform.chat.value + ' <img src='http://forum.wmonline.com.br/public/style_emoticons/default/biggrin.gif' class='bbc_emoticon' alt=':D' /> '; break; case 4: document.chatform.chat.value = document.chatform.chat.value + ' >( '; break; case 5: document.chatform.chat.value = document.chatform.chat.value + ' 8) '; break; case 6: document.chatform.chat.value = document.chatform.chat.value + ' <img src='http://forum.wmonline.com.br/public/style_emoticons/default/tongue.gif' class='bbc_emoticon' alt=':P' /> '; break; case 7: document.chatform.chat.value = document.chatform.chat.value + ' ??? '; break; case 8: document.chatform.chat.value = document.chatform.chat.value + ' :<img src='http://forum.wmonline.com.br/public/style_emoticons/default/smile.gif' class='bbc_emoticon' alt=':)' /> '; break; case 9: document.chatform.chat.value = document.chatform.chat.value + ' :-[ '; break; case 10: document.chatform.chat.value = document.chatform.chat.value + ' :-X '; break; case 11: document.chatform.chat.value = document.chatform.chat.value + ' :-* '; break; case 12: document.chatform.chat.value = document.chatform.chat.value + ' :\'( '; break; case 13: document.chatform.chat.value = document.chatform.chat.value + ' :-\\\ '; break; case 14: document.chatform.chat.value = document.chatform.chat.value + ' <img src='http://forum.wmonline.com.br/public/style_emoticons/default/wink.gif' class='bbc_emoticon' alt=';)' /> '; break; } document.chatform.chat.focus(); } function doSubmit() { if(document.chatform.chat.value == '') { alert('Please enter some text!'); document.chatform.chat.focus(); return false; } document.chatform.chat.value = document.chatform.chat.value; document.chatform.submit(); document.chatform.chat.value = ''; document.chatform.chat.focus(); return true; } </script> <?php } function showlogo() { global $HTTP_SESSION_VARS; global $skin; $activedir = "./style/"; @chdir($activedir); if ($skin=="") { print '<link rel="stylesheet" href="./style/yellow.css" type="text/css">';} else { ?> <link rel="stylesheet" href="<? echo $activedir.$skin; ?>" type="text/css"><? } ?> <body topmargin="0" leftmargin="0" marginwidth="0" marginheight="0"> <b>Chat V.0.95</b></a><br> <b>By <a href="http://www.orkut.com.br/Main#Profile.aspx?uid=15446353553944723892&rl=t" title="DJ Panik" target="_blank">DJ Panik</a></b></a><br> <? } function ShowAddPosts() { global $HTTP_SESSION_VARS; global $chat; global $nick; global $timeoutseconds; global $timestamp; global $timeout; global $skin; $activedir = "./style/"; @chdir($activedir); $timeoutseconds = 250; // Timeout value in seconds $timestamp=time(); $timeout=$timestamp-$timeoutseconds; print '<meta http-equiv="refresh" content="10;URL=index.php?action=posts&nick=<?php echo $nick; ?>">'; echo '<body topmargin="0" leftmargin="0" marginwidth="0" marginheight="0">'; if ($skin=="") { print '<link rel="stylesheet" href="./style/yellow.css" type="text/css">';} else { ?> <link rel="stylesheet" href="<? echo $activedir.$skin; ?>" type="text/css"><? } include ("config.php"); $svrConn = mysql_connect("$host", "$user", "$pass") or die("<b>Error:</b> Couldnt connect to database"); $dbConn = mysql_select_db("$base", $svrConn) or die ("<b>Error:</b> Couldnt connect to database"); $chat = strip_tags($chat,'<i><b><a>'); if(!empty($chat)) { $strQuery = "insert into chatScript values(0, '$chat','$nick','$timestamp')"; mysql_query($strQuery); } $strQuery = ("DELETE FROM chatScript WHERE timestamp<$timeout") or die("$useronline $base DELETE Error"); mysql_query($strQuery); $strQuery = "select theText, theNick from chatScript order by pk_Id asc"; $chats = mysql_query($strQuery); echo '<table border="0" width="100%" height="100%" cellpadding="1"> <tr><td valign="top" align="left" width="80%" height="100%" class="chattext">'; while($chatline = mysql_fetch_array($chats)) { print "<font size=\"2\"><b>" . $chatline["theNick"] . ":</b> " . swapFaces($chatline["theText"]) . "</b></i></font><br>"; } echo '</td></tr></table>'; ?> <script language="JavaScript"> scroll(10,600) </script> <? } function showusers() { global $HTTP_SESSION_VARS; global $nick; global $skin; $activedir = "./style/"; @chdir($activedir); print '<meta http-equiv="refresh" content="15;URL=index.php?action=users">'; echo '<body topmargin="0" leftmargin="0" marginwidth="0" marginheight="0">'; if ($skin=="") { print '<link rel="stylesheet" href="./style/yellow.css" type="text/css">';} else { ?> <link rel="stylesheet" href="<? echo $activedir.$skin; ?>" type="text/css"><? } echo '<table border="0" width="100%" height="100%" cellpadding="1" > <tr>'; echo '<td nowrap valign="top" align="left" width="400px" height="50%" class="online"><b>Usuários Online:</b><br>'; include ("config.php"); $svrConn = mysql_connect("$host", "$user", "$pass") or die("<b>Error:</b> Couldnt connect to database"); $dbConn = mysql_select_db("$base", $svrConn) or die ("<b>Error:</b> Couldnt connect to database"); $nicks = array(); $strQuery = "select theNick from chatScript order by theNick asc"; $chats = mysql_query($strQuery); while($chatline = mysql_fetch_array($chats)) { if (!in_array($chatline['theNick'],$nicks)) { $nicks[] = $chatline['theNick']; print "" . $chatline["theNick"] . "<br>"; } } echo '</td></tr></table>'; } function swapFaces($chatLine) { $chatLine = str_replace(":<img src='http://forum.wmonline.com.br/public/style_emoticons/default/smile.gif' class='bbc_emoticon' alt=':)' />", "<img src='./img/rolleyes.gif'>", $chatLine); $chatLine = str_replace("<img src='http://forum.wmonline.com.br/public/style_emoticons/default/smile.gif' class='bbc_emoticon' alt=':)' />", "<img src='./img/smile.gif'>", $chatLine); $chatLine = str_replace("<img src='http://forum.wmonline.com.br/public/style_emoticons/default/sad.gif' class='bbc_emoticon' alt=':(' />", "<img src='./img/frown.gif'>", $chatLine); $chatLine = str_replace("<img src='http://forum.wmonline.com.br/public/style_emoticons/default/biggrin.gif' class='bbc_emoticon' alt=':D' />", "<img src='./img/bigsmile.gif'>", $chatLine); $chatLine = str_replace(">(", "<img src='./img/angry.gif'>", $chatLine); $chatLine = str_replace("8)", "<img src='./img/cool.gif'>", $chatLine); $chatLine = str_replace("<img src='http://forum.wmonline.com.br/public/style_emoticons/default/tongue.gif' class='bbc_emoticon' alt=':P' />", "<img src='./img/tongue.gif'>", $chatLine); $chatLine = str_replace("???", "<img src='./img/huh.gif'>", $chatLine); $chatLine = str_replace(":-[", "<img src='./img/embarassed.gif'>", $chatLine); $chatLine = str_replace(":-X", "<img src='./img/lipsrsealed.gif'>", $chatLine); $chatLine = str_replace(':-\\', '<img src=\'./img/undecided.gif\'>', $chatLine); $chatLine = str_replace(":-*", "<img src='./img/kiss.gif'>", $chatLine); $chatLine = str_replace(":'(", "<img src='./img/cry.gif'>", $chatLine); $chatLine = str_replace("<img src='http://forum.wmonline.com.br/public/style_emoticons/default/wink.gif' class='bbc_emoticon' alt=';)' />", "<img src='./img/wink.gif'>", $chatLine); return $chatLine; } ?>
Consegui resolver uma parte desse problema, porém agora está ocorrendo o seguinte erro:
Parse error: syntax error, unexpected $end in C:\xampp\htdocs\chat\index.php on line 370
Alguém pode me ajudar? abraço!
Ping De Host Em Php
31/03/2010, 14:44
Oi pessoal.
Estou trabalhando em desenvolver um codigo em php que faça o ping em um determinado nº de IP, e obtenha a resposta se o link está online ou offline. Segue abaixo o codigo:
no código segue o comentário na parte que não está funcionando corretamente.
As linha de comando abaixo, deve ter alguma coisa errada.
$comando = $comando = "C:\windows\system32\ping -n 1 " . $ip;
$saida = shell_exec($comando); // comando do linux, mas não funciona no windows
Se tiver como alguém me ajudar. Obrigado!
<html>
<head>
<META HTTP-EQUIV="Refresh" CONTENT="60">
</head>
<body>
<h2>PAINEL DE MONITORAMENTO DE LINK</h2><br>
<?php
putenv("TZ=America/Sao Paulo");
$hora = date("d/m/y H:i:s");
echo ("$hora");
?>
<table border=1 cellspacing=6>
<tr>
<?php
$servidores = array (
"UNITELCO OSASCO" => "189.8.52.66",
"UNITELCO TABOÃO" => "200.150.228.10",
"SPEEDY OSASCO" => "200.171.16.157",
"SPEEDY TABOÃO" => "200.168.142.132"
);
$aux = 0;
while (list($site,$ip) = each($servidores))
{
$comando = $comando = "C:\windows\system32\ping -n 1 " . $ip;
$saida = shell_exec($comando); // comando do linux, mas não funciona no windows
if($aux == 5)
{
echo "</tr><tr>";
}
echo "<td>".$site."<br>".$ip."<br>"."Status: ";
if ( ereg("bytes from",$saida) ) {
echo "ONLINE</td>";
} else {
echo "<font color=red>OFFLINE</font></td>";
}
$aux++;
}
?>
</tr>
</table>
</body>
</html>
Estou trabalhando em desenvolver um codigo em php que faça o ping em um determinado nº de IP, e obtenha a resposta se o link está online ou offline. Segue abaixo o codigo:
no código segue o comentário na parte que não está funcionando corretamente.
As linha de comando abaixo, deve ter alguma coisa errada.
$comando = $comando = "C:\windows\system32\ping -n 1 " . $ip;
$saida = shell_exec($comando); // comando do linux, mas não funciona no windows
Se tiver como alguém me ajudar. Obrigado!
<html>
<head>
<META HTTP-EQUIV="Refresh" CONTENT="60">
</head>
<body>
<h2>PAINEL DE MONITORAMENTO DE LINK</h2><br>
<?php
putenv("TZ=America/Sao Paulo");
$hora = date("d/m/y H:i:s");
echo ("$hora");
?>
<table border=1 cellspacing=6>
<tr>
<?php
$servidores = array (
"UNITELCO OSASCO" => "189.8.52.66",
"UNITELCO TABOÃO" => "200.150.228.10",
"SPEEDY OSASCO" => "200.171.16.157",
"SPEEDY TABOÃO" => "200.168.142.132"
);
$aux = 0;
while (list($site,$ip) = each($servidores))
{
$comando = $comando = "C:\windows\system32\ping -n 1 " . $ip;
$saida = shell_exec($comando); // comando do linux, mas não funciona no windows
if($aux == 5)
{
echo "</tr><tr>";
}
echo "<td>".$site."<br>".$ip."<br>"."Status: ";
if ( ereg("bytes from",$saida) ) {
echo "ONLINE</td>";
} else {
echo "<font color=red>OFFLINE</font></td>";
}
$aux++;
}
?>
</tr>
</table>
</body>
</html>
Monitorar Link
19/02/2010, 14:29
Oi pessoal!
Estou tentando desenvolver um codigo em php para monitorar os links de internet na empresa.
Fiz em php o codigo para dar Pings nos IPs e está funcionando corretamente, mas não estou conseguindo associar ao email. Por exemplo, quando o link estiver offline enviar um email automaticamente para mim.
Segue o codigo em php que fiz:
<HTML>
<HEAD>
<TITLE> MONITORAMENTO LINK </TITLE>
</HEAD>
<BODY bgcolor='#54FF9F'>
<p><img src="Logo Atual.jpg" align="left" width="192" height="39" border="0"></p><br><br><br>
<font color="#0000CD"><b><i> MONITORAMENTO DE LINKS </i></b></font>
<br><br>
<font color="#1C1C1C"><b>
<?php
//data e hora
putenv("TZ=America/Sao_Paulo");
$hora = date("d/m/Y H:i:s");
// Comando PING
$ip = '189.8.52.66';
$ping = `ping $ip -n 1 -l 1`;
//Verifica se o computador respondeu
echo ("DATA / HORÁRIO: ");
echo ("$hora <br>");
if (eregi("bytes=", $ping)) {
echo ("LINK UNITELCO OSASCO $ip : ");
echo "<font color='#00008B'> STATUS ONLINE <br> </font>";
} else {
echo ("LINK UNITELCO OSASCO $ip : ");
echo "<font color='#FF0000'> STATUS OFFLINE <br> </font>";
}
?>
</font></b>
</body>
</html>
Se alguem puder me ajudar...
Abraço
Estou tentando desenvolver um codigo em php para monitorar os links de internet na empresa.
Fiz em php o codigo para dar Pings nos IPs e está funcionando corretamente, mas não estou conseguindo associar ao email. Por exemplo, quando o link estiver offline enviar um email automaticamente para mim.
Segue o codigo em php que fiz:
<HTML>
<HEAD>
<TITLE> MONITORAMENTO LINK </TITLE>
</HEAD>
<BODY bgcolor='#54FF9F'>
<p><img src="Logo Atual.jpg" align="left" width="192" height="39" border="0"></p><br><br><br>
<font color="#0000CD"><b><i> MONITORAMENTO DE LINKS </i></b></font>
<br><br>
<font color="#1C1C1C"><b>
<?php
//data e hora
putenv("TZ=America/Sao_Paulo");
$hora = date("d/m/Y H:i:s");
// Comando PING
$ip = '189.8.52.66';
$ping = `ping $ip -n 1 -l 1`;
//Verifica se o computador respondeu
echo ("DATA / HORÁRIO: ");
echo ("$hora <br>");
if (eregi("bytes=", $ping)) {
echo ("LINK UNITELCO OSASCO $ip : ");
echo "<font color='#00008B'> STATUS ONLINE <br> </font>";
} else {
echo ("LINK UNITELCO OSASCO $ip : ");
echo "<font color='#FF0000'> STATUS OFFLINE <br> </font>";
}
?>
</font></b>
</body>
</html>
Se alguem puder me ajudar...
Abraço
- Fórum WMO
- → Viewing Profile: Tópicos: colombo
- Privacy Policy
- Regras ·