Ver Mensaje Individual
  #1 (permalink)  
Antiguo 13/11/2010, 03:10
shiro51
 
Fecha de Ingreso: julio-2010
Mensajes: 34
Antigüedad: 13 años, 9 meses
Puntos: 0
ejecutar php almacenado en BD o tabla.

hola, hasta ahora he probado el eval code (aunque no lo entiendo al 100%), pero no me funciona correctamente, estoy haciendo un script que me carge las plantillas de las webs desde la base de datos y en las plantillas de la bd guardo php que se tiene que ejecutar luego, el problema del eval es que me ejecuta algunas variables pero no todas =S, por ejemplo:

El titulo del foro esta guardado en una tabla este la carga el setting.php y la muestra en las plantillas hasta hay bien pero en otra pagina donde se registra un usuario la plantilla le tiene que mostrar su datos de registro (user,pass,email...), pero me dice que no estan definidas y no encuentro el porque, hay alguna otra forma de hacerlo?.

informo que soy iniciado en php asi que tened paciencia conmigo xDDDD.

codigos:

TEMPLATES.PHP
Código PHP:
<?
include('setting.php');    
include(
'sesion.php');
    
if((!isset(
$Template)) or ($Template == '')) {echo 'Informe de este error a algun administrador';}

if( @
$Admin == 1)
{     
    
$Datos mysql_query("SELECT ID,template, template_msg FROM templates WHERE ID = 1 and template = 'Admin_template_$Template'"$conexion);
  
    while (
$row mysql_fetch_array($Datos))
    {  
    
$template_Admin $row['template_msg'];
    
$template_Admin ereg_replace'"''\\"'$template_Admin);
    
$template_Admin str_replace'['''$template_Admin);
    
$template_Admin str_replace']'''$template_Admin);
    eval(
"\$template_Admin = \"$template_Admin\";");
    echo 
$template_Admin;
    } 
    
  
}
//--------------------------------------
elseif( @$Mod == 2)
{
     
    
$Datos mysql_query("SELECT ID,template, template_msg FROM templates WHERE ID = 2 and template = 'Mod_template_$Template' "$conexion);
  
    while (
$row mysql_fetch_array($Datos))
    {  
    
$template_Mod $row['template_msg'];
    
$template_Mod ereg_replace'"''\\"'$template_Mod);
    
$template_Mod str_replace'['''$template_Mod);
    
$template_Mod str_replace']'''$template_Mod);
    eval(
"\$template_Mod = \"$template_Mod\";");
    echo 
$template_Mod;
    } 
 } 
//--------------------------------------
elseif( @$User == 3)
{
     
    
$Datos mysql_query("SELECT ID,template, template_msg FROM templates WHERE ID = 3 and template = 'User_template_$Template' "$conexion);
  
    while (
$row mysql_fetch_array($Datos))
    {  
    
$template_User $row['template_msg'];
    
$template_User ereg_replace'"''\\"'$template_User);
    
$template_User str_replace'['''$template_User);
    
$template_User str_replace']'''$template_User);
    eval(
"\$template_User = \"$template_User\";");
    echo 
$template_User;
    } 
 } 
 
 
//--------------------------------------
else
{    
    
$Datos mysql_query("SELECT ID,template, template_msg FROM templates WHERE ID = 4 and template = 'Visitor_template_$Template' "$conexion);
  
    while (
$row mysql_fetch_array($Datos))
    {  
    
$template_Visitor $row['template_msg'];
    
$template_Visitor ereg_replace'"''\\"'$template_Visitor);
    
$template_Visitor str_replace'['''$template_Visitor);
    
$template_Visitor str_replace']'''$template_Visitor);
    eval(
"\$template_Visitor = \"$template_Visitor\";");
    echo 
$template_Visitor;
    } 
 } 

?>
REGISTRO.PHP
Código PHP:
<? 

include('inc/setting.php');

if(!
function_exists('style'))
{
        function 
style($Template)
        {
        include(
'inc/templates.php');     
        }
}


if(
$_POST)
{
    
$user ereg_replace"([     ]+)"""$_POST['user']); //Remplazar espacios
    
$user ereg_replace">"""$user); //remplazar >
    
$user ereg_replace"<"""$user); //remplazar <
    
$user ereg_replace"\""""$user); //remplazar /
    
$user ereg_replace"'"""$user); //remplazar '
    
$user ereg_replace"#"""$user); //remplazar #
    
$user ereg_replace"$"""$user); //remplazar $ no funciona aun.
    
if($user == ''){ $Error_user_empty 1; } //si user esta vacio, Error_user es igual a 1
    
    
$user strtolower($user); //convertir cadena en minusculas
    //if(!isset($Error_user)){ echo 'bien'; }  //si la variable error_user no esta definida, mostramos bien. (ejemplo).
    
    
$clave ereg_replace"([     ]+)"""$_POST['clave']); //remplazamos espacios
    
if($clave == ''){ $Error_clave_empty 1; } //si clave esta vacia, Error_clave es igual a 1
    
if(strlen($clave) <= 6){ $Error_clave_small 1; } //si clave es menor a 6 caracteres decimos que error_clave_small es igual a 1
    
    
if(isset($Error_user_empty)){echo style('register_error_user_empty'); header('refresh:10; url=index.php?func=registro');}
    if(isset(
$Error_clave_empty)){echo style('register_error_clave_empty'); header('refresh:10; url=index.php?func=registro');}
    if(isset(
$Error_clave_small)){echo style('register_error_clave_small'); header('refresh:10; url=index.php?func=registro');}
    
    if((!isset(
$Error_user_empty)) && (!isset($Error_clave_empty)) && (!isset($Error_clave_small)))
        { 
        
$clave_original $clave;
        
$clave md5($clave);
     
        
$Datos mysql_query("SELECT Usuario FROM usuarios"$conexion);
            while (
$row mysql_fetch_array($Datos))
            { 
            
$BD_user $row['Usuario'];
            if(
$BD_user == $user){$Error_user_exist 1;}
            }
            
            if(isset(
$Error_user_exist)){echo style('register_user_exist'); header('refresh:10; url=index.php?func=registro');}
        
        
$Datos mysql_query("SELECT ID FROM usuarios"$conexion);
            while (
$row mysql_fetch_array($Datos)){ $ID $row['ID']; }
            @
$ID++;
            
            if(!isset(
$Error_user_exist)){
            
$fecha time(); 
            
$Datos mysql_query("INSERT INTO usuarios (ID, Usuario, Clave, Fecha, `Group`,Titulo) VALUES ($ID, '$user', '$clave', $fecha, 3, 'User')"$conexion);
            
setcookie("Mc-user",$user,time()+13536000);
            
setcookie("Mc-clave",$clave,time()+13536000);
            echo 
style('register_correct');
            
header('refresh:10; url=index.php');
            }
        
        }
    
//echo '<br>Seras redirigido a la pagina de inicio en <span id="contador">10</span> segundos o pulsa <a href="index.php">AQUI</a> para no esperar.';
}
 
?>

 <?
 
if(!($_POST))
        {
        echo 
style('register_form');
        }
 
?>
TABLA EN MYSQL CON PHP A EJECUTAR
Código HTML:
<html>
<head>
 <title>[$titulo]</title>
 <style type="text/css">
a:link,
a:visited{ text-decoration: none; color: #FFFFFF; }
a:active { text-decoration: underline; color: #FFFFFF; }
a:hover { text-decoration: underline;color: #FFFFFF; }
 </style>
 <script type="text/javascript">

var cont = 9;

function contador(){
if(cont > -1){
	var contador = document.getElementById("contador");
 contador.innerHTML = cont;
	cont--;
	}
}
</script>
</head>

<body style="background:#222;" onLoad="setInterval('contador()',1000);">
<center>
<div style="margin-top:150px; width:40%; color:#fff; background:#000; padding:10px; -moz-border-radius:10px;" align="left">

<span style="font-color:#fff;">Se completo el registro satisfactoriamente <br>Los datos de su registro son los siguientes: <br><br> <center>Usuario: <u>[$user]</u><br>Clave:<u>[$clave_original]</u></center>
	<br><br>Seras redirigido a la pagina de inicio en <span id="contador">10</span> segundos o pulsa <a href="index.php">AQUI</a> para no esperar.
</span>

</div>
</center>

</body>
</html> 
Gracias y saludos.