Usamos cookies para medir audiência e melhorar sua experiência. Você pode aceitar ou recusar a qualquer momento. Veja sobre o iMasters.
Colegas.
encontrei no site do thiago Clique aquiuma função que cria log das atividades do site. Ocorre que ao testar a função, nõa tenho tido retorno algum. Seguem abaixo o código da página de cadastro e o script que estou usando.
frmCadUsuario.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>Cadastro de usuários dos sistema</title>
<link href="css/niceforms-default.css" rel="stylesheet" type="text/css" />
<<script language="javascript" type="text/javascript" src="login1.0/niceforms.js"></script>
<link rel="stylesheet" type="text/css" media="all" href="login1.0/niceforms-default.css" />
</head>
<body>
<form action="login1.0/cadUsuario.php" method="post" name="form1" id="form1">
<div id="container">
<fieldset>
<legend> Cadastro de usuarios</legend>
<dl>
<dt><label for="nome">Nome:</label></dt>
<dd><input type="text" name="nome" id="nome" size="50" maxlength="128" />
</dd>
</dl>
<dl>
<dt><label for="usuario">Usuário:</label></dt>
<dd><input type="text" name="usuario" id="usuario" size="50" maxlength="128" />
</dd>
</dl>
<dl>
<dt><label for="senha">Senha:</label></dt>
<dd><input type="password" name="senha" id="senha" size="50" maxlength="128" />
</dd>
</dl>
<dl>
<dt><label for="email">email:</label></dt>
<dd><input type="text" name="email" id="email" size="50" maxlength="128" />
</dd>
</dl>
<dl>
<dt><label for="nivel">Nível:</label></dt>
<dd>
<label>
<select name="nivel" id="nivel">
<option value="1">Operador</option>
<option value="2">Administrador</option>
</select>
</label>
</dd>
</dl>
<dl>
<dt><label for="ativo">Ativo:</label></dt>
<dd><input type="text" name="ativo" id="ativo" size="50" maxlength="128" />
</dd>
</dl>
<input type="submit" value="Cadastrar Usuário" onclick="salvaLog()" />
</fieldset>
</div>
<input type="hidden" name="MM_insert" value="form1" />
</p>
<? var_dump( nome );?>
</form>
cadUsuario.php
<?php require_once('../Connections/conn.php'); ?>
<?php include('../log.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
$insertSQL = sprintf("INSERT INTO usuarios (nome, usuario, senha, email, nivel, ativo) VALUES (%s, %s, sha1(%s), %s, %s, %s)",
GetSQLValueString($_POST['nome'], "text"),
GetSQLValueString($_POST['usuario'], "text"),
GetSQLValueString($_POST['senha'], "text"),
GetSQLValueString($_POST['email'], "text"),
GetSQLValueString($_POST['nivel'], "int"),
GetSQLValueString($_POST['ativo'], "int"));
mysql_select_db($database_conn, $conn);
$Result1 = mysql_query($insertSQL, $conn) or die(mysql_error());
$insertGoTo = "../frmCadUsuario.php";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}
?>
log.php
<?
/**
* Função para salvar mensagens de LOG no MySQL
*
* @param string $mensagem - A mensagem a ser salva
*
* @return bool - Se a mensagem foi salva ou não (true/false)
*/
function salvaLog($mensagem) {
$ip = $_SERVER['REMOTE_ADDR']; // Salva o IP do visitante// Usamos o mysql_escape_string() para poder inserir a mensagem no banco
// sem ter problemas com aspas e outros caracteres
$mensagem = mysql_escape_string($mensagem);
// Monta a query para inserir o log no sistema
$sql = "INSERT INTO `logs` VALUES (NULL, '".$hora."', '".$ip."', '".$mensagem."')";
$mensagem = "Nova visita no site";echo "Não foi possível salvar o LOG!";
}
?>
Não ocorre erro mas também não é inserido o registro no sistema. podem me auxiliar?
Carregando comentários...