1
0

index.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <?php
  2. /**
  3. * dolphin. Collection of useful PHP skeletons.
  4. * Copyright (C) 2009 Johannes 'Banana' Keßler
  5. *
  6. * This program is free software: you can redistribute it and/or modify
  7. * it under the terms of the COMMON DEVELOPMENT AND DISTRIBUTION LICENSE
  8. *
  9. * You should have received a copy of the
  10. * COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0
  11. * along with this program. If not, see http://www.sun.com/cddl/cddl.html
  12. */
  13. mb_internal_encoding("UTF-8");
  14. if(ini_get("magic_quotes_gpc") == 1)
  15. die('Magic quotes is set to "on", and system is not able to change it. Please update Your php.ini file');
  16. /**
  17. * load the main configuration
  18. */
  19. require('conf/main.php');
  20. /**
  21. * require the function.library.inc.php
  22. * this holds global functions
  23. */
  24. require(PATH_LIB.'/function.library.php');
  25. /**
  26. * set the error reporting
  27. */
  28. if(DEBUG === true) {
  29. ini_set('error_reporting',-1); // E_ALL & E_STRICT
  30. ini_set('display_errors',true);
  31. }
  32. else {
  33. ini_set('error_reporting',-1); // E_ALL & E_STRICT
  34. ini_set('display_errors',false);
  35. ini_set('log_errors',true);
  36. ini_set('error_log',TMP_DIR.'/error/error.file');
  37. }
  38. /**
  39. * inlcude check and process before we output any content
  40. */
  41. $includeFile = false;
  42. if(!empty($_GET['p'])) {
  43. $check = validateString($_GET['p']);
  44. $check1 = file_exists('./site/script/'.$_GET['p'].'.php');
  45. if($check === true && $check1 === true) {
  46. $includeFile = './site/script/'.$_GET['p'].'.php';
  47. $template = $_GET['p'].'.html';
  48. }
  49. else {
  50. $includeFile = './site/script/error.php';
  51. $template = 'error.html';
  52. }
  53. }
  54. else {
  55. if(file_exists('./site/script/start.php')) {
  56. $includeFile = './site/script/start.php';
  57. }
  58. $template = 'start.html';
  59. }
  60. /**
  61. * setup smarty
  62. */
  63. require_once(PATH_LIB.'/smarty/Smarty.class.php');
  64. $smarty = new Smarty();
  65. $smarty->caching = 0;
  66. $smarty->setTemplateDir('site/template');
  67. $smarty->setCompileDir('site/cache/');
  68. $smarty->setCacheDir('site/cache/');
  69. /**
  70. * start a session
  71. * we only use cookies and do not allow the overwrite via get or post
  72. */
  73. if(ini_set('session.use_only_cookies',true) === false ||
  74. ini_set('session.cookie_httponly',true) === false ||
  75. ini_set('session.use_cookies',true) === false) {
  76. die('Cant use session cookies');
  77. }
  78. $garbage_timeout = SESSION_LIFETIME + 300;
  79. ini_set('session.gc_maxlifetime', $garbage_timeout);
  80. // the % rate how often the session.gc is run
  81. // http://de.php.net/manual/en/session.configuration.php#ini.session.gc-probability
  82. ini_set('session.gc_probability',10); // 100 = everytime = 100%
  83. session_set_cookie_params(SESSION_LIFETIME);
  84. session_name(SESSION_NAME);
  85. session_start();
  86. session_regenerate_id(true);
  87. /**
  88. * database connection
  89. * wihtout it it would be not working
  90. */
  91. require('./conf/db.php');
  92. $mysql_con = mysql_connect(DB_HOST,DB_USER,DB_PASSWORD) OR die('Datenbankserver nicht erreichbar');
  93. $mysql_sel = mysql_select_db(DB_DATABASE,$mysql_con) OR die('Datenbank konnte nicht selektiert werden');
  94. mysql_query("SET NAMES 'utf8'");
  95. // the main varible to store the data for the template
  96. $data = array();
  97. // load the script file
  98. if($includeFile !== false) {
  99. require($includeFile);
  100. }
  101. // the template we are using now to load the css and stuff correctly
  102. $smarty->assign(array('template_dir' => WEBROOT_PATH.'/site/template',
  103. 'img_path' => WEBROOT_PATH.'/site/template/img',
  104. 'template' => $template,
  105. 'data' => $data));
  106. if(!empty($data['_setHeader'])) {
  107. // this comes from the individual pages
  108. header($data['_setHeader']);
  109. }
  110. header('Content-type: text/html; charset=UTF-8');
  111. header("Date: ".gmdate("D, d M Y H:i:s", time())." GMT");
  112. header("Last-Modified: ".gmdate("D, d M Y H:i:s", time())." GMT");
  113. $smarty->display('main.html');
  114. ?>