header.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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/servers.php");
  12. require_once(DIR."/lib/opers.php");
  13. require_once(DIR."/lib/forms.php");
  14. require_once(DIR."/lib/configuration.php");
  15. if(!empty($_SERVER['HTTP_CLIENT_IP'])){
  16. $ip = $_SERVER['HTTP_CLIENT_IP'];
  17. }elseif(!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
  18. $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
  19. }elseif(!empty($_SERVER['REMOTE_ADDR'])){
  20. $ip = $_SERVER['REMOTE_ADDR'];
  21. }else{
  22. $ip = '';
  23. }
  24. define('USER_IP',$ip);
  25. function get_sql(){
  26. static $sql;
  27. if(!$sql){
  28. $sql = new mysqli(MYSQL_SERVER,MYSQL_USER,MYSQL_PASSWORD,MYSQL_DATABASE);
  29. if ($sql->connect_errno) {
  30. echo "Failed to connect to MySQL: (" . $sql->connect_errno . ") " . $sql->connect_error;
  31. die();
  32. }
  33. }
  34. return $sql;
  35. }
  36. function query($query,$args=Array()){
  37. $sql = get_sql();
  38. for ($i=0;$i<count($args);$i++){
  39. if(is_string($args[$i])){
  40. $args[$i] = $sql->real_escape_string($args[$i]);
  41. }elseif(!is_numeric($args[$i])){
  42. return false;
  43. }
  44. }
  45. return $sql->query(vsprintf($query,$args));
  46. }
  47. ?>