header.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. error_reporting(E_ALL);
  3. ini_set("display_errors", 1);
  4. session_start();
  5. define('DIR',dirname(__FILE__));
  6. require_once(DIR.'/lib/locale.php');
  7. require_once(DIR.'/config.php');
  8. require_once(DIR."/lib/irc.php");
  9. require_once(DIR."/lib/security.php");
  10. require_once(DIR."/lib/users.php");
  11. require_once(DIR."/lib/channels.php");
  12. require_once(DIR."/lib/servers.php");
  13. require_once(DIR."/lib/opers.php");
  14. require_once(DIR."/lib/forms.php");
  15. require_once(DIR."/lib/configuration.php");
  16. if(!empty($_SERVER['HTTP_CLIENT_IP'])){
  17. $ip = $_SERVER['HTTP_CLIENT_IP'];
  18. }elseif(!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
  19. $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
  20. }elseif(!empty($_SERVER['REMOTE_ADDR'])){
  21. $ip = $_SERVER['REMOTE_ADDR'];
  22. }else{
  23. $ip = '';
  24. }
  25. define('USER_IP',$ip);
  26. function get_sql(){
  27. static $sql;
  28. if(!$sql){
  29. $sql = new mysqli(MYSQL_SERVER,MYSQL_USER,MYSQL_PASSWORD,MYSQL_DATABASE);
  30. if ($sql->connect_errno) {
  31. echo "Failed to connect to MySQL: (" . $sql->connect_errno . ") " . $sql->connect_error;
  32. die();
  33. }
  34. }
  35. return $sql;
  36. }
  37. function query($query,$args=Array()){
  38. $sql = get_sql();
  39. for ($i=0;$i<count($args);$i++){
  40. if(is_string($args[$i])){
  41. $args[$i] = $sql->real_escape_string($args[$i]);
  42. }elseif(!is_numeric($args[$i])){
  43. return false;
  44. }
  45. }
  46. return $sql->query(vsprintf($query,$args));
  47. }
  48. ?>