header.php 1.4 KB

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