function get_sql_result($sql) { require_once "../../../php/sql_functions.php"; //function in php/sql_functions.php $conn = build_connection(); $result = mysqli_query($conn, $sql); //confirm_query($result); close_connection($conn); return $result; }
/** * Increments the number of times a profile has been viewed in the database. * Yay storing user data! */ public function increment_profile_view_counter() { $viewer_id = $this->viewer_user->user_row["UserID"]; $viewed_id = $this->viewed_user->user_row["UserID"]; // God I hate these sql queries $sql_query = 'INSERT INTO ' . Constant::profile_views_database_name . ' VALUES '; $sql_query .= '(' . $viewer_id . ', ' . $viewed_id . ', 1)'; $sql_query .= ' ON DUPLICATE KEY UPDATE `ProfileViews` = `ProfileViews` + 1;'; $connection = create_connection(); // process the query process_query($sql_query, $connection); close_connection($connection); }
<?php //build sql connection require_once "../../php/sql_functions.php"; $conn = build_connection(); $sql_select = "SHOW TABLES LIKE 'students'"; $query = @mysqli_query($conn, $sql_select); if (mysqli_num_rows($query) != 0) { echo "<p style='color: red'>Die Daten aus dem Letzten Jahr wurden noch nicht gelöscht!\n\t\tKlicke unter \"Aufräumen\" auf \"Daten des letzten Schuljahres löschen\" um Platz für einen neuen Durchlauf zu schaffen.</p>"; } else { close_connection($conn); //Setup a new database called "ferienschule" require 'create_database.php'; //build sql connection require_once "../../php/sql_functions.php"; //function in php/sql_functions.php $conn = build_connection(); //Add the tables "students", "topics", to the database require 'create_tables.php'; //Fills the table slots require 'init_slots.php'; close_connection($conn); //Fill the table "topics" with data from "data/themenliste.csv" require 'import_themenliste_excel.php'; }
print "</ul>"; print "<hr/>"; print "<h2>Actors! <a href='actor_form.php'>(Add)</a></h2>"; $random_actors_query = "select * from Actor order by rand() limit 5"; $random_actors = run_query($random_actors_query, $db_connection); print "<ul>"; while ($random_actor_row = mysql_fetch_array($random_actors, MYSQL_ASSOC)) { $actor_id = $random_actor_row['id']; $actor_tag = $random_actor_row['first'] . " " . $random_actor_row['last'] . " (" . $random_actor_row['dob'] . ")"; $actor_link = "actor.php?actor_id={$actor_id}"; print "<li><a href={$actor_link}>{$actor_tag}</a></li>"; } print "</ul>"; print "<hr/>"; print "<h2>Directors! <a href='director_form.php'>(Add)</a></h2>"; $random_directors_query = "select * from Director order by rand() limit 5"; $random_directors = run_query($random_directors_query, $db_connection); print "<ul>"; while ($random_director_row = mysql_fetch_array($random_directors, MYSQL_ASSOC)) { $director_id = $random_director_row['id']; $director_tag = $random_director_row['first'] . " " . $random_director_row['last'] . " (" . $random_director_row['dob'] . ")"; $director_link = "director.php?director_id={$director_id}"; print "<li><a href={$director_link}>{$director_tag}</a></li>"; } print "</ul>"; print "<hr/>"; close_connection($db_connection); print "</body>"; ?> </html>
/** * @param $user_id int The id of the user whose user row to retrieve from the database. * @return array The array containing the row of the user, if it exists. */ public static function get_user_row_by_id($user_id) { $sql_query = 'SELECT * FROM `' . Constant::user_database_name . '` '; $sql_query .= 'WHERE UserID="' . $user_id . '";'; $connection = create_connection(); // the user row with the particular id; it could be empty $user_row = process_query($sql_query, $connection, MYSQLI_ASSOC); // close the connection before exiting the function close_connection($connection); // returns an empty array if the user row doesn't exists return empty($user_row) ? array() : $user_row; }
<!-- end of content --> </div> <div id="footer"> </div> <?php close_connection(); ?> </body> </html>
function shutdown() { global $globals, $current_user, $db; close_connection(); if (is_object($db) && $db->connected) { Link::store_clicks(); // It will check cache and increment link clicks counter $db->close(); } if ($globals['access_log'] && !empty($globals['user_ip'])) { if (!empty($globals['script'])) { $script = $globals['script']; } elseif (empty($_SERVER['SCRIPT_NAME'])) { $script = 'null(' . urlencode($_SERVER["DOCUMENT_URI"]) . ')'; } else { $script = $_SERVER['SCRIPT_NAME']; } if (!empty($globals['ip_blocked'])) { $user = '******'; } elseif ($current_user->user_id > 0) { $user = $current_user->user_login; } else { $user = '******'; } if ($globals['start_time'] > 0) { $time = sprintf("%5.3f", microtime(true) - $globals['start_time']); } else { $time = 0; } @syslog(LOG_DEBUG, $globals['user_ip'] . ' ' . $user . ' ' . $time . ' ' . get_server_name() . ' ' . $script); exit(0); } }
function run_command($socket, $command, $multiprocess) { global $config, $eol, $rrdtool_pipe, $rrd_path, $php_binary_path, $rrd_update_path, $rrdupdates_in_process; $output = 'OK'; /* process the command, don't accept bad commands */ if (substr_count(strtolower($command), 'quit')) { close_connection($socket, 'Host Disconnect Request Received.'); return 'OK'; } elseif (substr_count(strtolower(substr($command, 0, 10)), 'update')) { /* ok to run */ } elseif (substr_count(strtolower(substr($command, 0, 10)), 'graph')) { /* ok to run */ } elseif (substr_count(strtolower(substr($command, 0, 10)), 'tune')) { /* ok to run */ } elseif (substr_count(strtolower(substr($command, 0, 10)), 'create')) { /* ok to run, check for structured paths */ if (read_config_option('extended_paths') == 'on') { $parts = explode(' ', $command); $data_source_path = $parts[1]; if (!is_dir(dirname($data_source_path))) { if (mkdir(dirname($data_source_path), 0775)) { if ($config['cacti_server_os'] != 'win32') { $owner_id = fileowner($config['rra_path']); $group_id = filegroup($config['rra_path']); if (chown(dirname($data_source_path), $owner_id) && chgrp(dirname($data_source_path), $group_id)) { /* permissions set ok */ } else { cacti_log("ERROR: Unable to set directory permissions for '" . dirname($data_source_path) . "'", FALSE); } } } else { cacti_log("ERROR: Unable to create directory '" . dirname($data_source_path) . "'", FALSE); } } } } elseif (substr_count(strtolower(substr($command, 0, 10)), 'status')) { close_connection($socket, 'Server Status OK'); return 'OK'; } else { close_connection($socket, "WARNING: Unknown RRD Command '" . $command . "' This activity will be logged!! Goodbye."); return 'OK'; } boost_svr_log("RRD Command '" . $command . "'"); /* update/create the rrd */ if (!$multiprocess) { boost_rrdtool_execute_internal($command, false, RRDTOOL_OUTPUT_STDOUT, 'BOOST SERVER'); } else { /* store the correct information in the array */ $rrdupdates_in_process[intval($socket)]['socket'] = $socket; if (strlen($rrd_update_path) && !substr_count($command, 'create ')) { $command = str_replace('update ', '', $command); exec_background($php_binary_path, 'boost_rrdupdate.php ' . intval($socket) . ' ' . $rrd_update_path . ' ' . $command); } else { exec_background($php_binary_path, 'boost_rrdupdate.php ' . intval($socket) . ' ' . $rrd_path . ' ' . $command); } } /* send the output back to the cleint if not multiprocess */ if (!$multiprocess) { socket_write($socket, $output . $eol, strlen($output . $eol)); } }
/** * Increments the number of times the user has logged in. */ public function increment_login_counter() { $user_id = $this->user_row[0]["UserID"]; $sql_query = 'INSERT INTO `' . Constant::login_count_database_name . '`(`UserID`, `LoginTimes`) '; $sql_query .= 'VALUES (' . $user_id . ', 1) ON DUPLICATE KEY UPDATE '; $sql_query .= '`LoginTimes` = `LoginTimes` + 1;'; $connection = create_connection(); process_query($sql_query, $connection); close_connection($connection); return $sql_query; }
public static function go() { ob_start(); // Global buffer start_benchmark('global'); // Determine URI string $path = str_ireplace("index.php", "", $_SERVER['PHP_SELF']); $uri = $_SERVER['REQUEST_URI']; if (stripos($uri, $path) === 0) { $uri = substr($uri, strlen($path)); } $uri = explode("?", $uri); $uri = rawurldecode(reset($uri)); use_library('text'); // Load up text modification functions. We'll need them for translation. use_library('files'); self::$segments = array_filter(explode("/", $uri)); // Split string into segments parse_str(parse_url($_SERVER['REQUEST_URI'], PHP_URL_QUERY), $_GET); // Apache rewrite might mess up our GET parameters. Let's just parse them ourselves. // Get current site based on URL $site = current_site(); // Redirect to HTTPS if needed if (Config::https() && !(isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on' || isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')) { redirect('https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']); } set_error_handler('_error_handler'); if ($site->live) { //ini_set('display_errors',1);error_reporting(-1); register_shutdown_function('_shutdown_handler'); // Set up function that will catch any coding errors } else { ini_set('display_errors', 1); error_reporting(-1); header("X-Robots-Tag: noindex, nofollow", true); // Prevent google from indexing us while we're not live yet } // Show admin page if requested if (segment(0) == ADMINDIR && Config::admin_enabled()) { array_shift(self::$segments); self::load_page_files(); // Load content pages require BASEPATH . 'admin/admin.php'; return FW4_Admin::show(); // Download file if requested } else { if (count(self::$segments) == 2 && self::segment(0) == '_download') { $file = where('id = %d', intval(self::segment(1)))->get_row('site/downloads'); if ($file) { force_download(FILESPATH . $file->filename, $file->orig_filename); exit; } else { return false; } // Determine which page to load } else { use_library('piwik'); Piwik::track_page_view(); register_shutdown_function(function () { close_connection(); Piwik::process(); }); // Load requested global libraries foreach (Config::global_libraries() as $library) { use_library($library); } $has_correct_language = self::determine_language(); self::load_page_files(); // Load content pages if (self::route(ROUTE_EARLY)) { return true; } if (!$has_correct_language) { self::language_redirect(); } if (self::route(ROUTE_DEFAULT)) { return true; } // If no segments are defined, apply default segments $orig_segments = self::$segments; if (!isset(self::$segments[0])) { self::$segments[0] = "home"; } if (!isset(self::$segments[1])) { self::$segments[1] = "index"; } if (self::route(ROUTE_DEFAULT)) { return true; } // There's no appropriate content with or without applying rules. Let's see if there's anything in the postprocessing rules. self::$segments = $orig_segments; if (self::route(ROUTE_LATE)) { return true; } // Absolutely nothing matches. No content exist for requested segments. return false; } } }
function run_command($socket, $command, $multiprocess) { global $config, $eol, $rrdtool_pipe, $rrd_path, $php_binary_path, $rrd_update_path, $rrdupdates_in_process; $output = "OK"; /* process the command, don't accept bad commands */ if (substr_count(strtolower($command), "quit")) { close_connection($socket, "Host Disconnect Request Received."); return "OK"; } elseif (substr_count(strtolower(substr($command, 0, 10)), "update")) { /* ok to run */ } elseif (substr_count(strtolower(substr($command, 0, 10)), "graph")) { /* ok to run */ } elseif (substr_count(strtolower(substr($command, 0, 10)), "tune")) { /* ok to run */ } elseif (substr_count(strtolower(substr($command, 0, 10)), "create")) { /* ok to run, check for structured paths */ if (read_config_option("extended_paths") == "on") { $parts = explode(" ", $command); $data_source_path = $parts[1]; if (!is_dir(dirname($data_source_path))) { if (mkdir(dirname($data_source_path), 0775)) { if ($config["cacti_server_os"] != "win32") { $owner_id = fileowner($config["rra_path"]); $group_id = filegroup($config["rra_path"]); if (chown(dirname($data_source_path), $owner_id) && chgrp(dirname($data_source_path), $group_id)) { /* permissions set ok */ } else { cacti_log("ERROR: Unable to set directory permissions for '" . dirname($data_source_path) . "'", FALSE); } } } else { cacti_log("ERROR: Unable to create directory '" . dirname($data_source_path) . "'", FALSE); } } } } elseif (substr_count(strtolower(substr($command, 0, 10)), "status")) { close_connection($socket, "Server Status OK"); return "OK"; } else { close_connection($socket, "WARNING: Unknown RRD Command '" . $command . "' This activity will be logged!! Goodbye."); return "OK"; } boost_svr_log("RRD Command '" . $command . "'"); /* update/create the rrd */ if (!$multiprocess) { boost_rrdtool_execute_internal($command, false, RRDTOOL_OUTPUT_STDOUT, "BOOST SERVER"); } else { /* store the correct information in the array */ $rrdupdates_in_process[intval($socket)]["socket"] = $socket; if (strlen($rrd_update_path) && !substr_count($command, "create ")) { $command = str_replace("update ", "", $command); exec_background($php_binary_path, "plugins/boost/boost_rrdupdate.php " . intval($socket) . " " . $rrd_update_path . " " . $command); } else { exec_background($php_binary_path, "plugins/boost/boost_rrdupdate.php " . intval($socket) . " " . $rrd_path . " " . $command); } } /* send the output back to the cleint if not multiprocess */ if (!$multiprocess) { socket_write($socket, $output . $eol, strlen($output . $eol)); } }