Subversion Repositories php_guestbook

Compare Revisions

Regard whitespace Rev 3 → Rev 4

/trunk/includes/database.inc.php
2,24 → 2,109
 
function verbinden() {
global $mysql_database, $mysql_server, $mysql_pass, $mysql_user;
global $link2;
 
$link2 = mysql_connect($mysql_server, $mysql_user, $mysql_pass);
if (!$link2) {
die('<b>Verbindung zum MySQL-Server konnte nicht hergestellt werden! ('.mysql_error().')</b>');
if (!db_connect($mysql_server, $mysql_user, $mysql_pass)) {
die('<b>Verbindung zum MySQL-Server konnte nicht hergestellt werden! ('.db_error().')</b>');
}
 
if (!mysql_select_db($mysql_database)) {
die('<b>Verbindung zum MySQL-Server konnte nicht hergestellt werden! ('.mysql_error().')</b>');
if (!db_select_db($mysql_database)) {
die('<b>Verbindung zum MySQL-Server konnte nicht hergestellt werden! ('.db_error().')</b>');
}
 
register_shutdown_function('trennen');
mysql_select_db($mysql_database);
db_select_db($mysql_database);
}
 
function trennen() {
global $link2;
@mysql_close($link2);
@db_close();
}
 
?>
// Liefert die Anzahl der Zeilen im Ergebnis
function db_num_rows($result) {
if (!$result) {
$err = db_error();
throw new Exception("Called db_num_rows() with an erroneous argument.".($err == '' ? '' : " Possible cause: $err"));
}
return $result->num_rows;
}
 
// Liefert eine Ergebniszeile als Objekt
function db_fetch_object($result, $class_name="stdClass", $params=null) {
if (!$result) {
$err = db_error();
throw new Exception("Called db_fetch_object() with an erroneous argument.".($err == '' ? '' : " Possible cause: $err"));
}
if ($params) {
return $result->fetch_object($class_name, $params);
} else {
return $result->fetch_object($class_name);
}
}
 
// Öffnet eine Verbindung zu einem MySQL-Server
function db_connect($server=null, $username=null, $password=null, $new_link=false, $client_flags=0) {
global $vts_mysqli;
$ary = explode(':', $server);
$host = $ary[0];
$ini_port = ini_get("mysqli.default_port");
$port = isset($ary[1]) ? (int)$ary[1] : ($ini_port ? (int)$ini_port : 3306);
if (is_null($server)) $port = ini_get("mysqli.default_host");
if (is_null($username)) $port = ini_get("mysqli.default_user");
if (is_null($password)) $port = ini_get("mysqli.default_password");
$vts_mysqli = new mysqli($host, $username, $password, /*dbname*/'', $port, ini_get("mysqli.default_socket"));
return (empty($vts_mysqli->connect_error) && ($vts_mysqli->connect_errno == 0)) ? $vts_mysqli : false;
}
 
// Schließt eine Verbindung zu MySQL
function db_close($link_identifier=NULL) {
global $vts_mysqli;
$li = is_null($link_identifier) ? $vts_mysqli : $link_identifier;
if (is_null($li)) throw new Exception("Cannot execute db_close(). No valid connection to server.");
 
return $li->close();
}
 
// Liefert den Fehlertext der zuvor ausgeführten MySQL Operation
function db_error($link_identifier=NULL) {
global $vts_mysqli;
$li = is_null($link_identifier) ? $vts_mysqli : $link_identifier;
if (is_null($li)) throw new Exception("Cannot execute db_error(). No valid connection to server.");
 
return !empty($li->connect_error) ? $li->connect_error : $li->error;
}
 
// Maskiert spezielle Zeichen innerhalb eines Strings für die Verwendung in einer SQL-Anweisung
function db_real_escape_string($unescaped_string, $link_identifier=NULL) {
global $vts_mysqli;
$li = is_null($link_identifier) ? $vts_mysqli : $link_identifier;
if (is_null($li)) throw new Exception("Cannot execute db_real_escape_string(). No valid connection to server.");
 
return $li->escape_string($unescaped_string);
}
 
// Sendet eine Anfrage an MySQL
function db_query($query, $link_identifier=NULL) {
global $vts_mysqli;
$li = is_null($link_identifier) ? $vts_mysqli : $link_identifier;
if (is_null($li)) throw new Exception("Cannot execute db_query(). No valid connection to server.");
 
return $li->query($query, $resultmode=MYSQLI_STORE_RESULT);
}
 
// Auswahl einer MySQL Datenbank
function db_select_db($database_name, $link_identifier=NULL) {
global $vts_mysqli;
$li = is_null($link_identifier) ? $vts_mysqli : $link_identifier;
if (is_null($li)) throw new Exception("Cannot execute db_select_db(). No valid connection to server.");
 
return $li->select_db($database_name);
}
 
// Liefert die ID, die in der vorherigen Abfrage erzeugt wurde
function db_insert_id($link_identifier=NULL) {
global $vts_mysqli;
$li = is_null($link_identifier) ? $vts_mysqli : $link_identifier;
if (is_null($li)) throw new Exception("Cannot execute db_insert_id(). No valid connection to server.");
 
return $li->insert_id;
}
/trunk/includes/ip_functions.inc.php
2,8 → 2,8
 
/*
* IP functions
* Copyright 2015 Daniel Marschall, ViaThinkSoft
* Version 2015-10-27
* Copyright 2015-2022 Daniel Marschall, ViaThinkSoft
* Version 2021-01-07
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
18,11 → 18,12
* limitations under the License.
*/
 
function get_real_ip() {
// Attention in re $allow_proxy: It is not secure to use these, since they are not validated: http://www.thespanner.co.uk/2007/12/02/faking-the-unexpected/
function get_real_ip($allow_proxy=false) {
/* Eindeutige IP Adresse erhalten, auch bei Proxies und (neu:) von SSH connections im CLI modus */
// http://lists.phpbar.de/pipermail/php/Week-of-Mon-20040322/007749.html
// Modificated by VTS
// Version: 2015-10-27
// Version: 2021-01-07
 
// TODO: ipv6
 
29,12 → 30,8
if (isset($_SERVER['SSH_CLIENT'])) { $ary = explode(' ', $_SERVER['SSH_CLIENT']); return $ary[0]; }
if (isset($_SERVER['SSH_CONNECTION'])) { $ary = explode(' ', $_SERVER['SSH_CONNECTION']); return $ary[0]; }
 
$client_ip = (isset($_SERVER['HTTP_CLIENT_IP'])) ? $_SERVER['HTTP_CLIENT_IP'] : '';
 
// It is not secure to use these, since they are not validated: http://www.thespanner.co.uk/2007/12/02/faking-the-unexpected/
// $x_forwarded_for = (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : '';
$x_forwarded_for = '';
 
$client_ip = ($allow_proxy && isset($_SERVER['HTTP_CLIENT_IP'])) ? $_SERVER['HTTP_CLIENT_IP'] : '';
$x_forwarded_for = ($allow_proxy && isset($_SERVER['HTTP_X_FORWARDED_FOR'])) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : '';
$remote_addr = (isset($_SERVER['REMOTE_ADDR'])) ? $_SERVER['REMOTE_ADDR'] : '';
 
if (!empty($client_ip)) {