Usamos cookies para medir audiência e melhorar sua experiência. Você pode aceitar ou recusar a qualquer momento. Veja sobre o iMasters.
Criem 2 pastas uma com o nome Connetions e outra com o nome admin dentro desta pasta admin criem outra pasta com o nome img
agora dentro da pasta "admin" vamos criar os arquivos
-->index.php
-->cadastrar.php
-->gerenciar.php
-->editar.php
-->excluir.php
-->logout.php
-->menu.php
-->protect.php
Primeiro criaremos a index.php
<?php
include('../Connections/connect.php');
session_start();
?>
<?php
if(!isset($_SESSION['login']) and !isset($_SESSION['senha'])){
}
else{
echo "<script>location.href='menu.php'</script>";
}
?>
<!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=utf-8" />
<title>index</title>
</head>
<style>
#login{
position:absolute;
width:159px;
height:135px;
left: 7px;
top: 11px;
}
</style>
<body>
<div id="login" width="200">
<fieldset>
<legend>Administração</legend>
<table width="160" height="120">
<form name="login" action="" method="post">
<tr>
<td width="191" height="43">Login:
<input name="login" type="text" size="25" maxlength="25" /></td>
<tr><td>senha:
<input name="senha" type="password" size="25" maxlength="25" /></td></tr><tr><td> <input name="submit" type="submit" value="Entrar" /></p></td></td>
</tr>
</form>
<?php
if(isset($_POST['submit'])==1){
$login = str_replace("'","", $_POST['login']);
$senha = str_replace("'","",$_POST['senha']);
$_SESSION['login'] = $login;
$_SESSION['senha'] = $senha;
$sql = mysql_query("select * from admin where login = '$login' and senha = '$senha'");
if(mysql_num_rows($sql) == 0){
echo "nao foi encontrado registro";
}else{
echo "<script>location.href='menu.php'</script>";
}
}
?>
</table>
</fieldset>
</div>
</body>
</html>
depois faremos a parte de cadastrar
cadastrar.php
<?php include("../Connections/connect.php") ?>
<?php
include ('protect.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=utf-8" />
<title>cadastrar</title>
</head>
<body>
<form action="#" method="post" enctype="multipart/form-data" name="cadastrar">
<table width="406" border="1">
<tr>
<th width="103" scope="col">Login :</th>
<td width="287">
<input type="text" name="login" id="login" /> </td>
</tr>
<tr>
<th scope="row">Senha :</th>
<td><label>
<input type="password" name="senha" id="senha" />
</label></td>
</tr>
<tr>
<th scope="row">Foto :</th>
<td><label>
<input type="file" name="foto" id="foto" />
</label></td>
</tr>
<tr>
<th scope="row">Email :</th>
<td><label>
<input type="text" name="email" id="email" />
</label></td>
</tr>
<tr>
<th colspan="2" valign="top" scope="row">Mensagem
<textarea name="msg" id="msg" cols="45" rows="5"></textarea></th>
</tr>
<tr>
<th colspan="2" scope="row"><label>
Clique aqui para cadastrar
<input type="submit" name="submit" id="submit" value="Cadastrar" />
</label></th>
</tr>
</table>
<?php
if(isset($_POST['submit'])==1){
$login = $_POST['login'];
$senha = $_POST['senha'];
$email = $_POST['email'];
$foto_name = $_FILES['foto']['name'];
$caminho = "img/".$foto_name;
$foto = $foto_name;
$msg = $_POST['msg'];
$sql = mysql_query("
INSERT INTO `qlegalweb`.`admin` (
`id` ,
`login` ,
`senha` ,
`foto` ,
`email` ,
msg
)
VALUES (
NULL , '$login', '$senha', '$email', '$foto', '$msg'
)");
if($sql == true){
move_uploaded_file($_FILES['foto']['tmp_name'],$caminho);
echo "foi cadastrado com sucesso <a href='index.php'>clique aqui.</a>";
}else{
echo "ocorreu um erro ao cadastrar";
}
}
?>
</form>
</body>
</html>
logo faremos a gerenciar
gerenciar.php
<?php include('../Connections/connect.php'); ?>
<?php
include ('protect.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=utf-8" />
<title>gerenciar</title>
<style>
table{
border:2px;
border-style:solid;
color:#FF0000;
}
th{
background-color:#003366;
color:#FFFFFF;
}
</style>
</head>
<body>
<h1 align="center">Administração</h1>
<hr color="#FF0000" />
<table width="396" cellpadding="1" cellspacing="0" align="center">
<tr>
<th>ID</th><th>Login</th><th>Senha</th><th>Email</th><th>Foto</th><th>Mensagem</th><th colspan="2">Opções</th>
</tr>
<?php
$sql = mysql_query("select * from admin");
while($linha = mysql_fetch_array($sql)){
$id = $linha['id'];
$login = $linha['login'];
$senha = $linha['senha'];
$email = $linha['email'];
$foto = $linha['foto'];
$msg = $linha['msg'];
echo "
<tr>
<td>$id</td><td>$login</td><td>$senha</td><td>$email</td><td><a href='img/".$foto."'><img src='img/".$foto."' width='50px' height='50px'></a></td><td>$msg</td><td><a href='editar.php?id=$id'><img src='img/editar.png' title='Editar'></a></td><td><a href='excluir.php?id=$id'><img src='img/excluir.gif' title='Excluir'></a></td>
<br>
</tr>
";
}
?>
</table>
<a href="menu.php">Voltar</a>
</body>
</html>
depois faremos a editar
editar.php
<?php include("../Connections/connect.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=utf-8" />
<title>cadastrar</title>
</head>
<body>
<?php
$id = $_GET['id'];
$sql = mysql_query("select * from admin where id=$id");
$separar = mysql_fetch_array($sql);
$login_old = $separar['login'];
$senha_old = $separar['senha'];
$email_old = $separar['email'];
$foto_old = $separar['foto'];
$msg_old = $separar['msg'];
?>
<form action="#" method="post" enctype="multipart/form-data" name="cadastrar">
<table width="406" border="1">
<tr>
<th width="103" scope="col">Login :</th>
<td width="287">
<input type="text" name="login" id="login" value="<?php echo $login_old; ?>" /> </td>
</tr>
<tr>
<th scope="row">Senha :</th>
<td><label>
<input type="password" name="senha" id="senha" value="<?php echo $senha_old; ?>" />
</label></td>
</tr>
<tr>
<th scope="row">Email :</th>
<td><label>
<input type="text" name="email" id="email" value="<?php echo $email_old; ?>" />
</label></td>
</tr>
<tr>
<th scope="row">Foto :</th>
<td><label>
<input type="file" name="foto" id="foto" value="<?php echo $foto_old; ?>"/>
</label></td>
</tr>
<tr>
<th colspan="2" valign="top" scope="row">Mensagem
<textarea name="msg" id="msg" cols="45" rows="5"><?php echo $msg_old; ?></textarea></th>
</tr>
<tr>
<th colspan="2" scope="row"><label>
Clique aqui para cadastrar
<input type="submit" name="submit" id="submit" value="Atualizar" />
</label></th>
</tr>
</table>
<?php
if(isset($_POST['submit'])==1){
$login = $_POST['login'];
$senha = $_POST['senha'];
$email = $_POST['email'];
$foto_name = $_FILES['foto']['name'];
if($foto_name == ''){
$foto_name .= $foto_old;
}
$caminho = "img/".$foto_name;
$foto = $foto_name;
$msg = $_POST['msg'];update admin set `login` = '$login',`senha` = $senha , `foto` = '$foto' ,`email` = '$email' ,`msg` = '$msg' where id = $id
");
if($sql == true){
move_uploaded_file($_FILES['foto']['tmp_name'],$caminho);
echo "<script>location.href='gerenciar.php'</script>";
}else{
echo "ocorreu um erro ao cadastrar";
}
}
?>
</form>
</body>
</html>
depois faremos a excluir
excluir.php
<?php
include('../Connections/connect.php');
$id = $_GET['id'];
$sql = mysql_query("delete from admin where id = $id");
if($sql == true){
$sql2 = mysql_query("select * from downloads id= $id");
$separar = mysql_fetch_assoc($sql2);
$caminho = $separar['foto'];
unlink("img/$caminho");
echo "<script>location.href='gerenciar.php'</script>";
}
?>
agora faremos a logout
logout.php
<?php
session_start();
session_destroy();
session_unset();
echo "<script>location.href='index.php'</script>";
?>
enfim faremos a proteção
protect.php
<?php
if(!isset($_SESSION['login']) and !isset($_SESSION['senha'])){
echo "<script>location.href='index.php'</script>";
}
?>
agora a parte de logado vou chamar de menu
menu.php
<?php
include('../Connections/connect.php');
?>
<?php
include ('protect.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=utf-8" />
<title>menu</title>
</head>
<body>
<h2>Seja Bem-Vindo <?php echo $_SESSION['login'] ?></h2><hr />
<ul>
<li><a href="gerenciar.php">Gerenciar</a></li>
<li><a href="cadastrar.php">Cadastrar Novo ADM</a></li>
<li><a href="../downloads/Gerenciar.php">Gerenciar Downloads</a></li>
<li><a href="../downloads/postar.php">Postar Downloads</a></li>
<li><a href="logout.php">Logout</a></li>
</ul>
</body>
</html>
a parte de conexao com o banco de dados nome do banco eu coloquei qlegalweb
na pasta Connections vamos criar um arquivo dentro desta pasta com o nome connect.php
<?php
$con = mysql_connect("localhost", "root", "") or die("erro ao se conectar com o banco de dadods");
mysql_select_db("qlegalweb",$con);
@session_start();
?>
a sql do banco de dados é essa
admin.sql
-- phpMyAdmin SQL Dump
-- version 3.2.4
-- http://www.phpmyadmin.net
--
-- Servidor: localhost
-- Tempo de Geração: Jan 06, 2011 as 11:19
-- Versão do Servidor: 5.1.41
-- Versão do PHP: 5.3.1
SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
--
-- Banco de Dados: qlegalweb
--
-- --------------------------------------------------------
--
-- Estrutura da tabela admin
--
CREATE TABLE IF NOT EXISTS `admin` (
`id` int(2) NOT NULL AUTO_INCREMENT,
`login` varchar(100) NOT NULL,
`senha` varchar(100) NOT NULL,
`foto` varchar(100) NOT NULL,
`email` varchar(100) NOT NULL,
`msg` text NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `login` (`login`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=10 ;
--
-- Extraindo dados da tabela admin
--
INSERT INTO admin (id, login, senha, foto, email, msg) VALUES
(6, 'CrY', '123456', 'SAM_1229 depois.jpg', 'Charleycesar@gmail.com', 'Bom Galera sou CrY administrador e dono do site'),
(9, 'Rafa', 'teste', 'capa.jpg', 'teste de email', 'aki eu vou por a msg');
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;Carregando comentários...