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

Hola,
Ise este foro para mandarlo cqui.
¿Que tiene este foro?
Vasicamente es una mejora del foro de este tutorial.
¿Que mejoras tiene?
  • Sistema de registro y reconocimiento de usuario
  • Codigos como [ b ] y [ u ]
  • Seguridad mejorada
  • Instalacion automatica
  • y mucho mas
El codigo es medio largo y usa mysql.
Empezemos:
index.php

Código PHP:
<meta http-equiv="Pragma" content="no-cache" >
<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');
include(
'header.html');
$sql "SELECT id, autor, titulo, fecha, respuestas, ult_respuesta ";
$sql.= "FROM foro WHERE identificador=0 ORDER BY ult_respuesta DESC";
$rs mysql_query($sql$con);
if(
mysql_num_rows($rs)>0){
    
// Leemos el contenido de la plantilla de temas
    
$template implode(""file("temas.html"));
    include(
'titulos.html');
    while(
$row mysql_fetch_assoc($rs))
    {
        
$color=($color==""?"#F0F0F0":"");
        
$row["color"] = $color;
        
mostrarTemplate($template$row);
    }
}
include(
'footer.html');
?><title>Foro echo por pato</title>
install2.php

Código 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>Instalacion</title>
<style type="text/css">
<!--
body {
    background-color: #E2E2E2;
}
-->
</style></head>

<body>
<table width="668" border="2" align="center" cellpadding="2" cellspacing="2" bordercolor="#000000" bgcolor="#FFFFFF">
  <!--DWLayoutTable-->
  <tr>
    <td width="668" height="25"><div align="center"><strong>Instalacion parte 2 de 2 </strong></div></td>
  </tr>
  <tr>
    <td height="24" valign="top">
<?
$usu
=$_POST['usu'];
$clave=$_POST['clave'];
$bd=$_POST['bd'];
$dir=$_POST['dir'];
$cre=$_POST['checkbox'];
$base=$bd;
@
$conexion=mysql_connect ("$dir","$usu","$clave") or exit('No se pudo conectar al servidor');
@
mysql_select_db ($base$conexion) or exit('No se pudo conectar a la BD');

$crear="CREATE TABLE `foro` (";
$crear.="`id` int(7) NOT NULL auto_increment,";
$crear.="  `autor` varchar(200) NOT NULL default '',";
$crear.="  `titulo` varchar(200) NOT NULL default '',";
$crear.="  `mensaje` text NOT NULL,";
$crear.="`fecha` datetime NOT NULL default '0000-00-00 00:00:00',";
$crear.="`respuestas` int(11) NOT NULL default '0',";
$crear.=" `identificador` int(7) NOT NULL default '0',";
$crear.="   `ult_respuesta` datetime default NULL,";
$crear.="    KEY `id` (`id`)";
$crear.=") ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=12 ;";

$crear2="CREATE TABLE `usuarios` (";
$crear2.="  `id` int(30) NOT NULL auto_increment,";
$crear2.="    `nick` varchar(30) NOT NULL,";
$crear2.="  `clave` varchar(30) NOT NULL,";
$crear2.="  `email` varchar(30) NOT NULL,";
$crear2.="  `pais` varchar(30) NOT NULL,";
$crear2.="  `firma` varchar(30) NOT NULL,";
$crear2.="  PRIMARY KEY  (`id`)";
$crear2.=") ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=3 ;";

@
$foro=mysql_db_query ($base,$crear ,$conexion);
@
$user=mysql_db_query ($base,$crear2 ,$conexion);


if(
file_exists("configuracion.php")){
echo 
"<strong>El archivo configuracion.php ya existe</strong><br>";
  } else{
    
$jiw "configuracion.php";
 @
$aqw fopen($jiw"a+"); 
  
$sssw "<?
  \$bd_host = '$dir';
  \$bd_usuario = '$usu';
  \$bd_password = '$clave';
  \$bd_base = '$base';
  \$con = mysql_connect(\$bd_host, \$bd_usuario, \$bd_password);
  mysql_select_db(\$bd_base, \$con);
?>"

 @
$ghjw fwrite($aqw$sssw); 
  
fclose($aqw); 
  }
if(
file_exists("config.ini.php")){
echo 
"<strong>El archivo config.ini.php ya existe</strong><br>";
  } else{
  
$jiwd "config.ini.php";
 @
$aqwd fopen($jiwd"a+"); 
  
$ssswd "<?
\$dbhost='$dir'; 
\$dbusername='$usu'; 
\$dbuserpass='$clave'; 
\$dbname='$base'; 
\$tabla='usuarios';
mysql_connect (\$dbhost, \$dbusername, \$dbuserpass); 
mysql_select_db(\$dbname) or die('Cannot select database'); 
?>"

@
$ghjwd fwrite($aqwd$ssswd); 
  
fclose($aqwd); 
  }
if(!
$ghjwd){
echo 
"<strong><font color='#FF0000'>Eror al crear el archivo $jiwd <br></font></strong>";
}
else
{
 echo 
"<strong><font color='#009933'>Archivo $jiwd creado correctamente <br></font></strong>";
}


if(!
$ghjw){
echo 
"<strong><font color='#FF0000'>Eror al crear el archivo $jiw <br></font></strong>";
}
else
{
 echo 
"<strong><font color='#009933'>Archivo $jiw creado correctamente <br></font></strong>";
}




if(!
$foro){
 echo 
"<strong><font color='#FF0000'>Eror al crear la tabla del foro</font></strong><br>";
  
$key2='no';
 } else{
 echo 
"<strong><font color='#009933'>Tabla del Foro creada correctamente.</font><br></strong>";
 
$key2='si';
 }
if(!
$user){ 
echo 
"<strong><font color='#FF0000'>Eror al crear la tabla de los usuarios</font><br></strong>";
 
$key='no';
 } else{
 echo 
"<strong><font color='#009933'>Tabla del Usuario creada correctamente.</font><br></strong>";
 
$key='si';
 }
         
mysql_close($conexion);
 if(
$key == 'si' and $key2 == 'si'){
unlink('install.html');
unlink('install2.php');
unlink('create.php');
echo 
"Se a borrado los archivos de instalacion";
  }
?></td>
  </tr>
</table>
</body>
</html>
intall.html

Código HTML:
<!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>Instalacion</title>
<style type="text/css">
<!--
body {
	background-color: #E2E2E2;
}
-->
</style></head>

<body>
<table width="668" border="2" align="center" cellpadding="2" cellspacing="2" bordercolor="#000000" bgcolor="#FFFFFF">
  <!--DWLayoutTable-->
  <tr>
    <td width="668" height="25"><div align="center"><strong>Instalacion parte 1 de 2 </strong></div></td>
  </tr>
  <tr>
    <td height="253" valign="top"><strong><fieldset><legend>Rellene los siguientes datos para instalar:</legend>
      <form id="form1" name="form1" method="post" action="install2.php">Direccion del servidor:<br>
        <input name="dir" type="text" id="dir" value="localhost" /><br>Usuario:<br>
        <input name="usu" type="text" id="usu" />
        <br>Clave:<br>
        <input name="clave" type="password" id="clave" />
        <br>Base de datos:<br>
          <input name="bd" type="text" id="bd" />
          <br>
          <label></label>
          <label></label>
          <br>
          <strong>
          <input type="submit" name="Submit" value="Instalar" />
          </strong>
          <label>
          <input type="reset" name="Submit2" value="&lt;&lt;Borrar datos&gt;&gt;" />
      </form>
          <fieldset><legend>Crear BD</legend>
          <strong>Direccion del servidor:<br /><form action="create.php" method="post" name="form1" target="_blank" id="form1">
          <input name="dir2" type="text" id="dir2" value="localhost" />
          <br />
          Usuario:<br />
          <input name="usu2" type="text" id="usu2" />
          <br />
          Clave:<br />
          <input name="clave2" type="password" id="clave2" />
          <br />
          Base de datos:<br />
          <input name="bd2" type="text" id="bd2" />
          <br />
          <label></label>
          <label></label>
          <br />
<strong>
<input type="submit" name="Submit3" value="Crear" />
</strong>
<label>
<input type="reset" name="Submit22" value="&lt;&lt;Borrar datos&gt;&gt;" />
          </form>
          </fieldset>
    </fieldset>
    </strong> </td>
  </tr>
</table>
</body>
</html> 
titulos_post.html
Código HTML:
<table width="90%" border="1" align="center" cellpadding="2" cellspacing="2" bordercolor="#000000" bgcolor="#666666">
  <tr align="center"> 
    <td width="25%">Usuario</td>
    <td>Mensaje</td>
  </tr>
</table> 
titulos.html

Código HTML:
<table width="90%" border="0" align="center" cellpadding="2" cellspacing="2" bgcolor="#666666">
<tr> 
    <td><a href="foro.php?id=<?=$id?>"> T&iacute;tulo</a></td>
    <td width="15%" align="center">Autor</td>
    <td width="15%" align="center"> Respuestas</td>
    <td width="15%" align="center"> &Uacute;lt. Mensaje</td>
  </tr>
</table> 
temas.html
Código HTML:
<table width="90%" border="1" align="center" cellpadding="2" cellspacing="2" bordercolor="#000000" bgcolor="#8A8A8A">
<tr> 
    <td><a href="foro.php?id=<?=$id?>">
      <?=$titulo?>
      </a></td>
    <td width="15%" align="center"><font size="-2">Por <b> 
      <?=$autor?>
      </b><br>
      el 
      <?=$fecha?>
      </font></td>
    <td width="15%" align="center"><font size="-2"> 
      <?=$respuestas?>
      </font></td>
    <td width="15%" align="center"><font size="-2"> 
      <?=$ult_respuesta?>
      </font></td>
  </tr>
</table> 
salir.php
Código PHP:
<?   
session_start
();   
if(!isset(
$_SESSION['s_username'])){   
header("location: entra.html");   
} else {   
session_unset();   
session_destroy();   
header("location: index.php");   
}   
?>
Continua en el proximo post.....
__________________
Half Music - www.halfmusic.com