Ver Mensaje Individual
  #3 (permalink)  
Antiguo 04/03/2008, 15:48
Avatar de pato12
pato12
 
Fecha de Ingreso: septiembre-2007
Ubicación: Salta
Mensajes: 1.620
Antigüedad: 17 años
Puntos: 101
Re: APORTE: Crea tu foro con php

inicio.html
Código HTML:
<table width="90%" border="1" align="center" cellpadding="2" cellspacing="2" bordercolor="#000000" bgcolor="#8A8A8A">
  <tr>
    <td><? include("$id.php"); ?></td>
  </tr>
</table> 
header.html
Código HTML:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>El Foro de Pato12</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

</head>

<body bgcolor="#9999cc" text="#FFFFFF" link="#FFFFFF">
<table width="90%" border="0" align="center" cellpadding="2" cellspacing="2" bgcolor="#000000">
  <tr>
    <td bgcolor="#666666"><h2>El foro de pato12 <br>
    </h2>
	<?
	if(isset($_SESSION['s_username'])){
	echo "Hola ".$_SESSION['s_username'];
	}
	else
	{
	echo "Bienvenido usuario";
	}
	?>
      <div align="right">[ <a href="index.php">Inicio</a> ]
	   <?
	   if(isset($_SESSION['s_username'])){
	   ?>
	   [ <a href="respuesta.php">Nuevo 
        Tema</a> ] [ <a href="salir.php">Salir</a> ]
        <? }else{ ?> [ <a href="inicio.php?id=reg">Registrar</a> ] [ <a href="inicio.php?id=log">Login</a> ]
        <? } ?>
    </div></td>
  </tr>
</table> 
agregar.php
Código PHP:
<?php
@session_start();
if(!isset(
$_SESSION['s_username'])){
echo 
"No estas logeado.";
}
else
{
require(
'configuracion.php');
$autor $_SESSION['s_username'];
$titulo $_POST["titulo"];
$mensaje $_POST["mensaje"];
$ident $_POST["identificador"];

//Hacemos algunas validaciones
if(empty($titulo)) $titulo "Sin título";
//Evitamos que el usuario ingrese HTML
$mensaje htmlentities($mensaje);

// Grabamos el mensaje en la base.
$sql "INSERT INTO foro (autor, titulo, mensaje, identificador, fecha, ult_respuesta) ";
$sql.= "VALUES ('$autor','$titulo','$mensaje','$ident',NOW(),NOW())";
$rs mysql_query($sql$con) or die("Error al grabar un mensaje: ".mysql_error);
$ult_id mysql_insert_id($con);

/* si es un mensaje en respuesta a otro
   actualizamos los datos */
if(!empty($ident))
{
    
$sql "UPDATE foro SET respuestas=respuestas+1, ult_respuesta=NOW()";
    
$sql.= " WHERE id = '$ident'";
    
$rs mysql_query($sql$con);
    
Header("Location: foro.php?id=$ident#$ult_id");
    exit();
}
Header("Location: index.php");
}
?>
create.php
Código PHP:
<? 
$usu
=$_POST['usu2'];
$clave=$_POST['clave2'];
$bd=$_POST['bd2'];
$dir=$_POST['dir2'];
$base="$bd";
$conexion=mysql_connect ("$dir","$usu","$clave");
if(
mysql_query"CREATE DATABASE  $base",$conexion)){
 echo 
"Base de datos $base creada";
}else{
echo 
"No se ha podido crear la base";
}
mysql_close($conexion);
?>
entrar.php
Código PHP:
<?
include('config.ini.php');
session_start(); 
if (
$_POST['username']) { 
//Comprobacion del envio del nombre de usuario y password 
$username=$_POST['username']; 
$password=$_POST['password']; 
if (
$password==NULL) { 
echo 
"La password no fue enviada"
}else{ 
$query mysql_query("SELECT nick,clave FROM usuarios WHERE nick = '$username'") or die(mysql_error()); 
$data mysql_fetch_array($query); 
if(
$data['clave'] != $password) { 
echo 
"Login incorrecto"
}else{ 
$query mysql_query("SELECT nick,clave FROM usuarios WHERE nick = '$username'") or die(mysql_error()); 
$row mysql_fetch_array($query); 
$_SESSION["s_username"] = $row['nick']; 
Header("Location: index.php");


}
?>
footer.html
Código HTML:
<table width="90%" border="0" align="center" cellpadding="2" cellspacing="2" bgcolor="#000000">
<tr>
    <td align="center" bgcolor="#666666">Foro echo por pato12</td>
  </tr>
</table>
</body>
</html> 
formulario.html
Código HTML:
<?
if(isset($_SESSION['s_username'])){
?>
<table width="90%" border="1" align="center" cellpadding="2" cellspacing="2" bordercolor="#000000" bgcolor="#666666">
<form name="f" action="agregar.php" method="post">
    <input type="hidden" name="identificador" value="<?=$id?>">
    <tr> 
      <td width="26%" align="right">Titulo</td>
      <td colspan="2"><input type="text" name="titulo" value="<?=$titulo?>" /></td>
    </tr>
    <tr> 
      <td width="26%" align="right">Mensaje</td>
      <td width="36%"><textarea name="mensaje" cols="50" rows="5"><?=$mensaje?></textarea></td>
      <td width="38%" align="left" valign="top">Comandos permitidos:<br>
        <strong>[b] texto [/b]</strong><br>
        [citar] Texto [/citar]<br>
        [i] <em>Texto</em> [/i]<br>
        [php] Codigo PHP [/php]</td>
    </tr>
    <tr> 
      <td width="26%" align="right">&nbsp;</td>
      <td colspan="2"><input type="submit" name="Submit" value="Enviar Mensaje" /></td>
    </tr>
  </form>
</table>
<?
}
else
{
echo "No estas logeado";
}
?> 
foro.php
Código PHP:
<style type="text/css">
<!--
body {
    background-color: #F0F0F0;
}
a:link {
    color: #FFFFFF;
}
a:visited {
    color: #FFFFFF;
}
a:hover {
    color: #CCCCCC;
}
a:active {
    color: #FF0000;
}
-->
</style><?php
@session_start();
require(
'configuracion.php');
require(
'funciones.php');
$id $_GET["id"];
if(empty(
$id)) Header("Location: index.php");

$sql "SELECT id, autor, titulo, mensaje, ";
$sql.= "DATE_FORMAT(fecha, '%d/%m/%Y %H:%i:%s') as enviado FROM foro ";
$sql.= "WHERE id='$id' OR identificador='$id' ORDER BY fecha ASC";
$rs mysql_query($sql$con);
include(
'header.html');
if(
mysql_num_rows($rs)>0)
{
    include(
'res.html');
    include(
'titulos_post.html');
    
$template implode(""file('post.html'));
    while(
$row mysql_fetch_assoc($rs))
    {
    
$firma=$row["firma"];
        
$color=($color==""?"#5b69a6":"");
        
$row["color"] = $color;
        
//manipulamos el mensaje
        
$row["mensaje"] = nl2br($row["mensaje"]);
        
$row["mensaje"] = parsearTags($row["mensaje"]);
        
mostrarTemplate($template$row);
    }
}
include(
'footer.html');
?>
Continua en el siguente post....
__________________
Half Music - www.halfmusic.com

Última edición por pato12; 04/03/2008 a las 15:55