Código PHP:
if ((isset($_GET['doLogout'])) &&($_GET['doLogout']=="true")){
//to fully log out a visitor we need to clear the session varialbles
$_SESSION['MM_Username'] = NULL;
$_SESSION['MM_UserGroup'] = NULL;
Código PHP:
<?php require_once('Connections/libre.php'); ?>
<?php
if (!isset($_SESSION)) {
session_start();
}
?>
<?php
ini_set("display_errors", 1);
error_reporting (E_ALL & ~E_NOTICE);
include_once 'db.php';
function filtraUserInput()
{
if(isset($_POST)) foreach($_POST as $key => $value) $_POST[$key] = $value;
if(isset($_GET)) foreach($_POST as $key => $value) $_GET[$key] = $value;
}
function conectaDB($server, $user, $password, $db)
{
if(!$con = mysql_connect($server, $user, $password)) return false;
if(!$db = mysql_select_db($db)) return false;
filtraUserInput();
return $con;
}
function obtenerimagenUsuario($con, $user_id){
$sql = "SELECT U.imagen FROM libre U WHERE U.id = '$user_id';";
$query = mysql_query($sql, $con);
$fetch = mysql_fetch_assoc($query);
return $fetch['imagen'];
}
function login($conec, $user, $password){
$sql = "SELECT * FROM libre U WHERE (U.nombre_user = '{$user}' AND U.password = '{$password}');";
if(!$query = mysql_query($sql, $conec)) die(mysql_error());
if(1 == mysql_num_rows($query))
{
session_start();
$fetch = mysql_fetch_assoc($query);
foreach($fetch as $key => $value) $_SESSION[$key] = $value;
}
return true;
}
function logout(){return true;}
function enviarMensaje($con, $from, $to, $subject, $body)
{
$sql = "insert into `messages`
(`subject`,`body`,`to`,`from`,`sended_on`,`read`,`folder_id`,`owner`)
values
('$subject','$body','$to','{$_SESSION['id']}',NOW(),'0','1','$to')";
if(!$query = mysql_query($sql, $con)) return false;
$sql = "insert into `messages`
(`subject`,`body`,`to`,`from`,`sended_on`,`read`,`folder_id`,`owner`)
values
('$subject','$body','$to','{$_SESSION['id']}',NOW(),'0','2','{$_SESSION['id']}')";
if(!$query = mysql_query($sql, $con)) return false;
return true;
}
function eliminarMensaje($con, $mensaje){
$sql = "DELETE FROM messages WHERE id = '$mensaje';";
return mysql_query($sql, $con);
}
function moverMensaje($con, $mensaje, $carpeta)
{
$sql = "UPDATE messages SET folder_id = '$carpeta' WHERE id = '$mensaje';";
return mysql_query($sql, $con) or die(mysql_error());
}
function obtenerMensaje($con, $mensaje, $owner)
{
$sql = "SELECT * FROM messages M WHERE M.owner = '$owner' AND M.id = '$mensaje';";
if(!mysql_num_rows(mysql_query($sql, $con))) return 0;
else return mysql_fetch_assoc(mysql_query($sql, $con));
}
function listarCarpeta($con, $user_id, $carpeta)
{
$sql = "SELECT * FROM messages M WHERE M.owner = '$user_id' AND M.folder_id = '$carpeta';";
if(!mysql_num_rows(mysql_query($sql, $con))) return 0;
else return mysql_query($sql, $con);
}
function obtenerNombreCarpeta($con, $carpeta_id)
{
$sql = "SELECT F.nombre FROM folders F WHERE id = '$carpeta_id';";
$query = mysql_query($sql, $con);
$fetch = mysql_fetch_assoc($query);
return $fetch['nombre'];
}
function obteneridUsuario($con, $user_id){
$sql = "SELECT U.id FROM libre U WHERE U.id = '$user_id';";
$query = mysql_query($sql, $con);
$fetch = mysql_fetch_assoc($query);
return $fetch['id'];
}
function obtenerNombreUsuario($con, $user_id){
$sql = "SELECT U.nombre FROM libre U WHERE U.id = '$user_id';";
$query = mysql_query($sql, $con);
$fetch = mysql_fetch_assoc($query);
return $fetch['nombre'];
}
function listarUsuarios($con)
{
$sql = "SELECT * FROM libre U";
if(!mysql_query($sql, $con)) return false;
return mysql_query($sql, $con);
}
function listarCarpetas($con)
{
$sql = "SELECT * FROM folders F";
if(!mysql_query($sql, $con)) return false;
return mysql_query($sql, $con);
}