[PHP Class] Sistema de noticias By Doddy H

Iniciado por BigBear, Julio 03, 2011, 09:51:40 PM

Tema anterior - Siguiente tema

0 Miembros y 1 Visitante están viendo este tema.


Hola a todos

Acabo de hacer mi segunda POO en php , se trata de un simple sistema
de noticias llamada "noticion" xDDD

Apararentemente es segura contra SQLI , y posee las siguientes funciones para manejar noticias

  • Conectar con la DB

    Código: php

    datos("server","user","pass","db","tabla","columna id","columna titulo","columna contenido","columna fecha")


  • Crear noticia con

    Código: php

    crear("id","titulo","contenido","fecha")


  • Eliminar noticia con

    Código: php

    eliminar("id de la noticia")


  • Ver contenido de noticia

    Código: php

    ver("id de la noticia")


    Devuelve un array con el que pueden ver cada columna con sus datos

  • Modificar contenido de noticia

    Código: php

    mod("nuevo id","nuevo titulo","nuevo contenido","nueva fecha")


    Eso seria todo

    Codigo de noticion.php

    Código: php

    <?php

    /*

    Noticion 0.3

    (c) DOddy Hackman 2010


    Anti SQLI

    */


    class noticion {


    private $host;
    private $db;
    private $user;
    private $pass;
    private $tabla;
    private $id;
    private $titulo;
    private $contenido;
    private $fecha;
    private $x_id;
    private $x_titulo;
    private $x_contenido;
    private $_fecha;
    private $tit;
    private $con;
    private $fech;



    public function datos($host,$user,$pass,$db,$tabla,$id,$titulo,$contenido,$fecha) {
    $this->host = $host;
    $this->db = $db;
    $this->user = $user;
    $this->pass = $pass;
    $this->tabla = $tabla;
    $this->id = $id;
    $this->titulo = $titulo;
    $this->contenido = $contenido;
    $this->fecha = $fecha;
    $test = mysql_connect($host,$user,$pass);
    @mysql_select_db($db,$test);

    }

    public function eliminar($id) {
    if (is_numeric($id)) {
    if (@mysql_query("DELETE FROM ".$this->tabla." where id='".$id."'")) {
    return true;
    }
    }
    }

    public function nuevo($x_id,$x_titulo,$x_contenido,$x_fecha) {
    if (is_numeric($x_id)) {
    if (@mysql_query("INSERT INTO ".$this->tabla."(".$this->id.",".$this->titulo.",".$this->contenido.",".$this->fecha.")values('".$x_id."','".$x_titulo."','".$x_contenido."','$x_fecha')")) {
    return true;
    }
    }
    }

    public function ver($id) {
    if (is_numeric($id)) {
    if ($que = @mysql_query("SELECT ".$this->id.",".$this->titulo.",".$this->contenido.",".$this->fecha." FROM ".$this->tabla." WHERE ".$this->id."='".$id."'")) {
    while ($ver = @mysql_fetch_array($que)) {
    return array($ver[0],$ver[1],$ver[2],$ver[3]);
    }
    }
    }
    }

    public function mod($id,$tit,$con,$fech) {
    if (is_numeric($id)) {
    if (@mysql_query("UPDATE ".$this->tabla." SET ".$this->id."="."'".$id."'".",".$this->titulo."="."'".$tit."'".",".$this->contenido."="."'".$con."'".",".$this->fecha."="."'".$fech."'"." where id='".$id."'")) {
    return true;
    }
    }
    }

    public function close() {
    $test->close;
    }


    }

    ?>


    Ejemplo de uso

    noticia.php

    Código: php

    <?php


    include("noticion.php");
    $noti = New noticion;
    $noti->datos("localhost","root","123","noticias","noticia","id","titulo","cotenido","fecha");
    //$noti->nuevo("3","hola","dfdfdfdf","5465465");
    $noti->eliminar("'");

    if ($noti->mod("3","holax","dfdfdfdf","5465465")) {
    echo "cambiado<br><br>";
    }

    if ($ver = $noti->ver(3)) {
    echo $ver[1]."<br>";
    }



    //}

    //if ($noti->mod("1","cambie","cambie,"cambie")) {
    //echo "cambiado";
    //}



    Como siempre , cualquier falla ,vulnerabilidad ,sugerencia  seran
    bienvenidas para la mejora de la clase