Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [PHP] Problem przy integracji z forum
Forum PHP.pl > Forum > Przedszkole
Orish
Próbuję samodzielnie zintegrować logowanie w moim serwisie z forum phpbb3, ale moje pytanie jest bardziej ogólne.

Mam plik index.php:

  1. <?php
  2. header('Content-Type: text/html; charset=iso-8859-2');
  3.  
  4. define('RUNNING' , 1);
  5. define('SKIN_NAME' , 'darktower');
  6. define('SRC_DIR' , './sources/');
  7. define('CLASS_DIR' , SRC_DIR . 'classes/');
  8. define('SUB_DIR' , SRC_DIR . 'sub/');
  9. define('HTML_DIR' , './skin/' . SKIN_NAME . '/');
  10. //Tells PhpBB we're not hackers. Includes the common.php file from the forums.
  11. define('IN_PHPBB', true);
  12. $phpbb_root_path = '../forum/';
  13. $phpEx = substr(strrchr(__FILE__, '.'), 1);
  14. include($phpbb_root_path . 'common.' . $phpEx);
  15.  
  16. // Start session management. This allows us access to some of the user's information when they are logged in.
  17. $user->session_begin();
  18. $auth->acl($user->data);
  19. $user->setup();
  20.  
  21. //Some common thing's you'll use. $username gives the username, and $userid gives the unique ID of the loggedin user.
  22. $username = $user->data['username'];
  23. $userid = $user->data['user_id'];
  24.  
  25.  
  26. require_once 'config.php';
  27. require_once SRC_DIR . 'functions.php';
  28.  
  29. $input = getInput();
  30.  
  31. require_once CLASS_DIR . 'class_mysql.php';
  32. require_once CLASS_DIR . 'class_core.php';
  33.  
  34. $db = new mysql($sql['host'], $sql['login'], $sql['passw'], $sql['db']);
  35.  
  36. $res = $db->query('SELECT * FROM `config`');
  37.  
  38. while(!$res->EOF)
  39. {
  40. $config[$res->field['name']] = $res->field['content'];
  41.  
  42. $res->moveNext();
  43. }
  44.  
  45. $sess = new session;
  46.  
  47. if(empty($input['page']))
  48. {
  49. $input['page'] = 'wiesci';
  50. }
  51. else
  52. {
  53. $input['page'] = basename($input['page']);
  54.  
  55. if(!file_exists(SUB_DIR . $input['page'] . '.php'))
  56. {
  57. $input['page'] = 'wiesci';
  58. }
  59. }
  60.  
  61. require SUB_DIR . $input['page'] . '.php';
  62.  
  63. $screen = new SubPage($db, $sess, $config, $input);
  64. $screen->msg($message);
  65.  
  66. // Po co niby destruktor...
  67. $screen->finalDisplay();
  68. ?>


I jak mogę sprawić, żeby zmienne $username itd. działały także w innych plikach, np. class_core.php?

  1. <?php
  2. class core
  3. {
  4. public $html = '';
  5. public $db = NULL;
  6. public $sess = NULL;
  7. public $input = array();
  8. public $config = array();
  9. public $tpl = array();
  10. public $subpage;
  11. public $global_msg = '';
  12. public $access;
  13. protected $online = null;
  14. public $noTemplate = 0;
  15.  
  16. protected $groups = false;
  17.  
  18. public function __construct($db, $sess, $config, $input)
  19. {
  20. $this->db = $db;
  21. $this->sess = $sess;
  22. $this->config = $config;
  23. $this->input = $input;
  24. $this->access = $this->getUserAccessLevel($user->data['site_id']);
  25.  
  26. $this->loadSkin();
  27. }
  28.  
  29. public function finalDisplay()
  30. {
  31. $this->runSubPage();
  32.  
  33. if($this->config['page_enabled'] == 0 && !$this->config['disabled_page'])
  34. {
  35. die ( '<br /><br /><center>' . $this->config['disabled_message'] . '</center>');
  36. }
  37. elseif($this->config['page_enabled'] == 0 && $this->config['disabled_page'])
  38. {
  39. header('Location: ' . $this->config['disabled_page']);
  40. }
  41.  
  42. if($this->noTemplate == 0)
  43. {
  44. $out = $this->tpl['page_index'];
  45.  
  46. $out = str_replace('<%HEADER%>' , $this->tpl['header'] , $out );
  47. $out = str_replace('<%HTML_START%>', $this->tpl['html_start'] , $out );
  48. $out = str_replace('<%PAGE_TOP%>' , $this->tpl['page_top'] , $out );
  49. $out = str_replace('<%PAGE_LEFT%>' , $this->tpl['page_left'] , $out );
  50. $out = str_replace('<%LOGIN_BOX%>' , $user->data['is_registered'] ? $this->tpl['loginbox_logged'] : $this->tpl['loginbox_not_logged'], $out);
  51. $out = str_replace('<%BANNERS%>' , $this->tpl['banners'] , $out );
  52. $out = str_replace('<%PAGE_MAIN%>' , $this->tpl['page_main'] , $out );
  53.  
  54. $out = str_replace('<%PAGE_FOOT%>' , $this->tpl['page_foot'] , $out );
  55. $out = str_replace('<%CATEGORY_LIST%>', $this->createCategoryList() , $out );
  56. $out = str_replace('<%POOL%>' , $this->createPool() , $out );
  57. $out = str_replace('<%LINKS%>' , $this->createLinks() , $out );
  58. $out = str_replace('<%BASE_HREF%>' , $this->config['base_href'] , $out );
  59. $out = str_replace('<%GLOBAL_TITLE%>' , $this->config['global_title'], $out );
  60.  
  61. $out = str_replace('<%SUBPAGE%>' , $this->getSubpageHtml(), $out);
  62. $out = str_replace('<%GLOBAL_MESSAGE%>', $this->global_msg , $out);
  63. $out = str_replace('<%TOP_NEWS%>' , $this->getTopNews() , $out);
  64. $out = str_replace('<%TOP_ARTS%>' , $this->getTopArts() , $out);
  65. }
  66. else
  67. {
  68. $out = $this->getSubpageHtml();
  69. }
  70.  
  71. echo $out;
  72. }
  73.  
  74. private function loadSkin ()
  75. {
  76. // Pobieramy glowny kod htmla z bazy
  77. $res = $this -> db -> select ( "html" );
  78. while ( !$res -> EOF )
  79. {
  80. $this -> tpl [$res -> field ['name']] = $res -> field ['html'];
  81. $res -> movenext();
  82. }
  83. }
  84.  
  85. function getSubpageHtml ()
  86. {
  87. return $this -> html;
  88. }
  89.  
  90. }
  91.  
  92. ?>
Orish
Prościej, tzn.? Te artykuły opisują tylko podstawę integracji sesji. Ja natomiast pytam o ogólną zasadę pozwalającą używać zmiennych z bazy forum w plikach klas i podstron ($input['page']).

up
emtiej
może przesyłaj te zmienne jako argumenty funkcji/konstruktora klasy ?
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.