Jump to content

[Clase PHP] Clase core php para empezar a crear tu web


Recommended Posts

Hola, les dejo con esta clase MySQL que les permitirá crear su propia CMS con conocimientos básicos sobre php y mysql. Cualquier duda comentar.

 

<!--?php


/**
* @author Zenok
* @page www.metin2zone.net
* @copyright Zenok
*/

class core
{
public static $string;

public function Init()
{
	session_start();
	$this->MySQL();
}
public function MySQL()
{
	$this->hostname = "localhost";
	$this->username = "root";
	$this->password = "TU_CONTRASEÑA";
	$this->database = "TU_DB";
	$this->connection = mysql_connect($this->hostname, $this->username, $this->password) or die(mysql_error());
	$this->connection = mysql_select_db($this->database) or die(mysql_error());
	return $this->connection;
}

public function String($string)
{
	$this->String = mysql_real_escape_string($string);
	$this->String = strip_tags($this->String);
	return $this->String;
}

public function User($string)
{
	$this->User = mysql_fetch_assoc(mysql_query("SELECT ".$string." FROM users WHERE id = '".$_SESSION['id']."'"));
	return $this->User[''.$string.''];
}

public function GetOnline()
{
	$this->Online = mysql_fetch_assoc(mysql_query("SELECT users_online FROM server_status"));
	return $this->Online['users_online'];
}
}

$core = new core();
$core->Init();


?>

 

- Init(): Inicia la clase PHP

- MySQL(): Inicia la conexión MySQL

- String(): Filtra las variables para evitar inyecciones SQL

- User(): Obtiene la información del usuario

- GetOnline(): Obtiene los usuarios conectados en la web

 

1.- Utilización de la clase

 

Es necesario que al principio de cada archivo se incluya la clase PHP para poder usarla de este modo:

 

<?php

require_once("includes/class_core.php");

?>

 

2.- Utilización de la clase

 

Para llamar a las funciones en tus códigos php tan solo necesitas realizarlo de este modo:

 

$core->Funcion();

 

Por ejemplo:

 

Seleccionar dato de usuario por post

<?php

$username = $core->String($_POST['username']);


mysql_query("SELECT id FROM users WHERE username = '$username'");

?>

 

Recojer usuarios online

 

<?php

echo $core->GetOnline();

?>

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...