Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [PHP]incude z subdomeny
Forum PHP.pl > Forum > Przedszkole
gokugo
Witam

Posiadam plik (dający wynik ostatnich postów na forum) pod adresem http://www.forum.skps.wroclaw.pl/noweposty.php .
Chciałbym go wczytać za pomocą polecenia include do pliku http://www.skps.wroclaw.pl/index1.php czyli includujemy plik z subdomeny.

teoretycznie powinno zadziałać:
  1. <?php include("../forum/noweposty.php"); ?>


praktycznie mam komunikaty zwrotne


Warning: main(common.php): failed to open stream: No such file or directory in /skps/web/forum/noweposty.php on line 6
Warning: main(): Failed opening 'common.php' for inclusion (include_path='') in /skps/web/forum/noweposty.php on line 6
Fatal error: Call to undefined function: request_var() in /skps/web/forum/noweposty.php on line 15

co widać na http://www.skps.wroclaw.pl/index1.php

dzięki za pomoc
Fifi209
No wyraźnie źle podałeś ścieżkę.
gokugo
widzisz fifi... problem polega w tym, że ścieżka jest prawidłowa
Fifi209
W takim razie może uprawnienia? Bo skoro nie może odczytać to albo uprawnienia albo ścieżka.
gokugo
Jesteś mi w stanie powiedzieć coś na temat tych uprawnieńquestionmark.gif
fr33d0m
Moim zdaniem to nie uprawnienia tylko ścieżka. 2dni temu w dziale PHP sam założyłem wątek z takimi samymi błędami jakie występują u Ciebie i problem tkwił w ścieżce dostępu. Napisz jak wygląda u Ciebie rozkład folderów bo subdomena za wiele nam nie mówi - można mieć subdomenę a folder w zupełnie innym miejscu zagnieżdżony.
Fifi209
Na subdomenie zrób sobie plik
[PHP] test.php - pobierz, plaintext
  1. <?php
  2.  
  3. echo dirname(__FILE__);
  4. ?>
[PHP] test.php - pobierz, plaintext

I go odpal, ten sam wrzuć na domenę gdzie chcesz includować i też odpal. Będziesz wiedział czy ścieżek nie poplątałeś.
przemo191
Albo zrób tak:

  1. <?php include("http://www.forum.skps.wroclaw.pl/noweposty.php"); ?>


smile.gif
Fifi209
Cytat(przemo191 @ 13.10.2011, 22:38:06 ) *
Albo zrób tak:

  1. <?php include("http://www.forum.skps.wroclaw.pl/noweposty.php"); ?>


smile.gif

A może potrzebuje jakiś zmiennych z tego pliku? :<
gokugo
Cytat
Albo zrób tak:
  1. pobierz, plaintext
  2. <?php include("http://www.forum.skps.wroclaw.pl/noweposty.php"); ?>


Przemo nie ma szans na przepuszczenie przez serwer linków zewnętrznych, a taki zapis jest niestety tak traktowany sad.gif

fifi & fr33d0m poszedłem za Waszymi radami:
lokalizacja pliku includowanego na subdomenie: /skps/web/forum/noweposty.php
lokalizacja docelowa, na którą chcemy includować: /skps/web/www/index.php

więc w pliku index.php w celu prawidłowego includowania powinienem jak dla mnie wpisać:

  1. <?php include("../forum/noweposty.php"); ?>


mam nadzieję, że się mylę biggrin.gif
Fifi209
Czytanie ze zrozumieniem podstawą sukcesu.
Jakby ktoś mądry zauważył wcześniej, plik jest includowany na co nie zwróciliśmy uwagi.
Jednakże w pliku noweposty.php jest include do pliku common.php, jeżeli otwierasz:
/skps/web/forum/noweposty.php
To nie ma problemu, bo w folderze forum jest noweposty.php i common.php
Jednak gdy wchodzisz na:
/skps/web/www/index.php i includujesz noweposty.php to noweposty.php szuka domyślnie w /skps/web/www/
zapis include('common.php'); jest traktowany jak ./common.php czyli szukaj w bieżącym folderze.

Podaj po prostu całą ścieżkę do include czyli /skps/web/forum/common.php
Swirek
implode(file("http://strona.com/dir/file.html"));

albo jeszcze lepiej

file_get_contents

pozdrawiam
Fifi209
Swirek, jak już wcześniej pisałem, może potrzebuje faktycznie include pliku?
gokugo
Cytat
Czytanie ze zrozumieniem podstawą sukcesu.
Jakby ktoś mądry zauważył wcześniej, plik jest includowany na co nie zwróciliśmy uwagi.
Jednakże w pliku noweposty.php jest include do pliku common.php, jeżeli otwierasz:
/skps/web/forum/noweposty.php
To nie ma problemu, bo w folderze forum jest noweposty.php i common.php
Jednak gdy wchodzisz na:
/skps/web/www/index.php i includujesz noweposty.php to noweposty.php szuka domyślnie w /skps/web/www/
zapis include('common.php'); jest traktowany jak ./common.php czyli szukaj w bieżącym folderze.

Podaj po prostu całą ścieżkę do include czyli /skps/web/forum/common.php


fifi: common.php to chyba dobry trop. Podmieniłem ściezkę dostępu do common.php tak jak sugerowałeś... coprawda nie działa ale mamy inny komunikat

Warning: Cannot modify header information - headers already sent by (output started at /skps/web/www/noweposty.php:1) in /skps/web/forum/common.php on line 163

wyjaśnienia: http://phpedia.pl/wiki/Cannot_add_header_i...rs_already_sent

niestety nie mam dostępu do php.ini
croc
Niektóre serwery nie pozwalają na schodzenie w strukturze plików niżej niż wywołana domena i żadne ../ wtedy nie zadziała, bo jako najniższy poziom traktowany jest najniższy w danej domenie/subdomenie.
Fifi209
Pokaż zatem kody plików, bo gdzieś przed nagłówkami musisz coś wyświetlać - stąd informacja.
gokugo
Cytat
Pokaż zatem kody plików, bo gdzieś przed nagłówkami musisz coś wyświetlać - stąd informacja.


fifi: proszę zatem kody plików. Jeżeli nic nie wskórasz to i tak jestem Twoim dłużnikiem smile.gif

lokalizacja docelowa, na którą chcemy includować: /skps/web/www/includujemy.php (http://www.skps.wroclaw.pl/icludujemy.php)
  1. <?php
  2. include("/skps/web/forum/noweposty.php");
  3. ?>


lokalizacja pliku includowanego na subdomenie: /skps/web/forum/noweposty.php (http://www.forum.skps.wroclaw.pl/noweposty.php)
  1. <?php
  2.  
  3. define('IN_PHPBB', true);
  4. $phpbb_root_path = '';
  5. $phpEx = substr(strrchr(__FILE__, '.'), 1);
  6. include($phpbb_root_path . '/skps/web/forum/common.' . $phpEx);
  7.  
  8. // Start session management
  9. //$user->session_begin();
  10. //$auth->acl($user->data);
  11. //$user->setup();
  12.  
  13. // Number of posts and grabbing permissions
  14. // Pocet prspevku pro zobrazen a oprvnen
  15. $topic_limit = request_var('topic_limit', 5);
  16. $forums = array_unique(array_keys($auth->acl_getf('f_read', true))); //ignored in sql statement to include all topics despite permissions
  17.  
  18. // Select the last topics based on user permissions
  19. /* $sql = 'SELECT p.post_id, p.topic_id, p.forum_id, p.post_subject, p.post_time, u.username
  20.   FROM ' . POSTS_TABLE . ' p , ' . USERS_TABLE . ' u
  21.   WHERE post_approved = 1
  22.   AND ' . $db->sql_in_set('forum_id', $forums) . '
  23.   AND u.user_id = p.poster_id
  24.   ORDER BY post_time DESC
  25.   LIMIT 0,' . $topic_limit;
  26.   $result = $db->sql_query($sql); */
  27.  
  28. // Select the last topics ignoring permissions
  29. // Vybrat posledn tmata ke kterm mme oprvnen
  30. $sql = 'SELECT p.post_id, p.topic_id, p.forum_id, p.post_subject, p.post_time, u.username
  31. FROM ' . POSTS_TABLE . ' p , ' . USERS_TABLE . ' u
  32. WHERE post_approved = 1
  33. AND u.user_id = p.poster_id
  34. ORDER BY post_time DESC
  35. LIMIT 0,' . $topic_limit;
  36. $result = $db->sql_query($sql);
  37.  
  38. // Proper header since output not buffered
  39. // Poslat hlavicky pro sprvn kdovn, protoe vpis obsahu je postupn
  40. // header('Content-Type: text/html; charset=utf-8');
  41.  
  42. // Now let's output the content
  43. // A ted vypsat obsah
  44. // echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>Last Topics</title></head><body><div id="post_content"><strong>Last Topics:</strong><br/><ul>';
  45. while ($row = $db->sql_fetchrow($result))
  46. {
  47. $url = generate_board_url() . "/viewtopic.{$phpEx}?f={$row['forum_id']}&amp;t={$row['topic_id']}&amp;p={$row['post_id']}#p{$row['post_id']}"; //added fedforum to url
  48.  
  49. //old line $url = generate_board_url() . "viewtopic.{$phpEx}?f={$row['forum_id']}&amp;t={$row['topic_id']}&amp;p={$row['post_id']}#p{$row['post_id']}";
  50. echo '<img src="../index_pliki/dol/strzalka_niebieska.gif"> <a target="_blank" href="' . $url . '">' . $row['post_subject'] . '</a>,<br> autor: ' . ucwords($row['username']) . ',<br> data: ' . date("d.m.Y",$row['post_time']).',<br> godzina: ' . date("H:i", $row['post_time']) . ' <br>';
  51. }
  52. echo '</div></body></html>';
  53. ?>





lokalizacja pliku common.php na subdomenie, do którego odwołuje się błąd : /skps/web/forum/common.php (http://www.forum.skps.wroclaw.pl/common.php)
  1. <?php
  2. /**
  3. *
  4. * @package phpBB3
  5. * @version $Id$
  6. * @copyright (c) 2005 phpBB Group
  7. * @license <a href="http://opensource.org/licenses/gpl-license.php" target="_blank">http://opensource.org/licenses/gpl-license.php</a> GNU Public License
  8. *
  9. * Minimum Requirement: PHP 4.3.3
  10. */
  11.  
  12. /**
  13. */
  14. if (!defined('IN_PHPBB'))
  15. {
  16. }
  17.  
  18. $starttime = explode(' ', microtime());
  19. $starttime = $starttime[1] + $starttime[0];
  20.  
  21. // Report all errors, except notices and deprecation messages
  22. if (!defined('E_DEPRECATED'))
  23. {
  24. define('E_DEPRECATED', 8192);
  25. }
  26. error_reporting(E_ALL ^ E_NOTICE ^ E_DEPRECATED);
  27.  
  28. /*
  29. * Remove variables created by register_globals from the global scope
  30. * Thanks to Matt Kavanagh
  31. */
  32. function deregister_globals()
  33. {
  34. $not_unset = array(
  35. 'GLOBALS' => true,
  36. '_GET' => true,
  37. '_POST' => true,
  38. '_COOKIE' => true,
  39. '_REQUEST' => true,
  40. '_SERVER' => true,
  41. '_SESSION' => true,
  42. '_ENV' => true,
  43. '_FILES' => true,
  44. 'phpEx' => true,
  45. 'phpbb_root_path' => true
  46. );
  47.  
  48. // Not only will array_merge and array_keys give a warning if
  49. // a parameter is not an array, array_merge will actually fail.
  50. // So we check if _SESSION has been initialised.
  51. if (!isset($_SESSION) || !is_array($_SESSION))
  52. {
  53. $_SESSION = array();
  54. }
  55.  
  56. // Merge all into one extremely huge array; unset this later
  57. $input = array_merge(
  58. array_keys($_GET),
  59. array_keys($_POST),
  60. array_keys($_COOKIE),
  61. array_keys($_SERVER),
  62. array_keys($_SESSION),
  63. array_keys($_ENV),
  64. array_keys($_FILES)
  65. );
  66.  
  67. foreach ($input as $varname)
  68. {
  69. if (isset($not_unset[$varname]))
  70. {
  71. // Hacking attempt. No point in continuing unless it's a COOKIE
  72. if ($varname !== 'GLOBALS' || isset($_GET['GLOBALS']) || isset($_POST['GLOBALS']) || isset($_SERVER['GLOBALS']) || isset($_SESSION['GLOBALS']) || isset($_ENV['GLOBALS']) || isset($_FILES['GLOBALS']))
  73. {
  74. }
  75. else
  76. {
  77. $cookie = &$_COOKIE;
  78. while (isset($cookie['GLOBALS']))
  79. {
  80. foreach ($cookie['GLOBALS'] as $registered_var => $value)
  81. {
  82. if (!isset($not_unset[$registered_var]))
  83. {
  84. unset($GLOBALS[$registered_var]);
  85. }
  86. }
  87. $cookie = &$cookie['GLOBALS'];
  88. }
  89. }
  90. }
  91.  
  92. unset($GLOBALS[$varname]);
  93. }
  94.  
  95. unset($input);
  96. }
  97.  
  98. // If we are on PHP >= 6.0.0 we do not need some code
  99. if (version_compare(PHP_VERSION, '6.0.0-dev', '>='))
  100. {
  101. /**
  102. * @ignore
  103. */
  104. define('STRIP', false);
  105. }
  106. else
  107. {
  108.  
  109. // Be paranoid with passed vars
  110. if (@ini_get('register_globals') == '1' || strtolower(@ini_get('register_globals')) == 'on' || !function_exists('ini_get'))
  111. {
  112. deregister_globals();
  113. }
  114.  
  115. define('STRIP', (get_magic_quotes_gpc()) ? true : false);
  116. }
  117.  
  118. if (defined('IN_CRON'))
  119. {
  120. $phpbb_root_path = dirname(__FILE__) . DIRECTORY_SEPARATOR;
  121. }
  122.  
  123. if (file_exists($phpbb_root_path . 'config.' . $phpEx))
  124. {
  125. require($phpbb_root_path . 'config.' . $phpEx);
  126. }
  127.  
  128. if (!defined('PHPBB_INSTALLED'))
  129. {
  130. // Redirect the user to the installer
  131. // We have to generate a full HTTP/1.1 header here since we can't guarantee to have any of the information
  132. // available as used by the redirect function
  133. $server_name = (!empty($_SERVER['HTTP_HOST'])) ? strtolower($_SERVER['HTTP_HOST']) : ((!empty($_SERVER['SERVER_NAME'])) ? $_SERVER['SERVER_NAME'] : getenv('SERVER_NAME'));
  134. $server_port = (!empty($_SERVER['SERVER_PORT'])) ? (int) $_SERVER['SERVER_PORT'] : (int) getenv('SERVER_PORT');
  135. $secure = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') ? 1 : 0;
  136.  
  137. $script_name = (!empty($_SERVER['PHP_SELF'])) ? $_SERVER['PHP_SELF'] : getenv('PHP_SELF');
  138. if (!$script_name)
  139. {
  140. $script_name = (!empty($_SERVER['REQUEST_URI'])) ? $_SERVER['REQUEST_URI'] : getenv('REQUEST_URI');
  141. }
  142.  
  143. // Replace any number of consecutive backslashes and/or slashes with a single slash
  144. // (could happen on some proxy setups and/or Windows servers)
  145. $script_path = trim(dirname($script_name)) . '/install/index.' . $phpEx;
  146. $script_path = preg_replace('#[\\\\/]{2,}#', '/', $script_path);
  147.  
  148. $url = (($secure) ? 'https://' : 'http://') . $server_name;
  149.  
  150. if ($server_port && (($secure && $server_port <> 443) || (!$secure && $server_port <> 80)))
  151. {
  152. // HTTP HOST can carry a port number...
  153. if (strpos($server_name, ':') === false)
  154. {
  155. $url .= ':' . $server_port;
  156. }
  157. }
  158.  
  159. $url .= $script_path;
  160. header('Location: ' . $url);
  161. }
  162.  
  163. if (defined('DEBUG_EXTRA'))
  164. {
  165. $base_memory_usage = 0;
  166. if (function_exists('memory_get_usage'))
  167. {
  168. $base_memory_usage = memory_get_usage();
  169. }
  170. }
  171.  
  172. // Load Extensions
  173. // dl() is deprecated and disabled by default as of PHP 5.3.
  174. if (!empty($load_extensions) && function_exists('dl'))
  175. {
  176. $load_extensions = explode(',', $load_extensions);
  177.  
  178. foreach ($load_extensions as $extension)
  179. {
  180. @dl(trim($extension));
  181. }
  182. }
  183.  
  184. // Include files
  185. require($phpbb_root_path . 'includes/acm/acm_' . $acm_type . '.' . $phpEx);
  186. require($phpbb_root_path . 'includes/cache.' . $phpEx);
  187. require($phpbb_root_path . 'includes/template.' . $phpEx);
  188. require($phpbb_root_path . 'includes/session.' . $phpEx);
  189. require($phpbb_root_path . 'includes/auth.' . $phpEx);
  190.  
  191. require($phpbb_root_path . 'includes/functions.' . $phpEx);
  192. require($phpbb_root_path . 'includes/functions_content.' . $phpEx);
  193.  
  194. require($phpbb_root_path . 'includes/constants.' . $phpEx);
  195. require($phpbb_root_path . 'includes/db/' . $dbms . '.' . $phpEx);
  196. require($phpbb_root_path . 'includes/utf/utf_tools.' . $phpEx);
  197.  
  198. // Set PHP error handler to ours
  199. set_error_handler(defined('PHPBB_MSG_HANDLER') ? PHPBB_MSG_HANDLER : 'msg_handler');
  200.  
  201. // Instantiate some basic classes
  202. $user = new user();
  203. $auth = new auth();
  204. $template = new template();
  205. $cache = new cache();
  206. $db = new $sql_db();
  207.  
  208. // Connect to DB
  209. $db->sql_connect($dbhost, $dbuser, $dbpasswd, $dbname, $dbport, false, defined('PHPBB_DB_NEW_LINK') ? PHPBB_DB_NEW_LINK : false);
  210.  
  211. // We do not need this any longer, unset for safety purposes
  212. unset($dbpasswd);
  213.  
  214. // Grab global variables, re-cache if necessary
  215. // www.phpBB-SEO.com SEO TOOLKIT BEGIN
  216. if (empty($phpbb_seo) ) {
  217. require_once($phpbb_root_path . 'phpbb_seo/phpbb_seo_class.'.$phpEx);
  218. $phpbb_seo = new phpbb_seo();
  219. @define('PHPBB_USE_BOARD_URL_PATH', true);
  220. }
  221. // www.phpBB-SEO.com SEO TOOLKIT END
  222. $config = $cache->obtain_config();
  223.  
  224. // Add own hook handler
  225. require($phpbb_root_path . 'includes/hooks/index.' . $phpEx);
  226. $phpbb_hook = new phpbb_hook(array('exit_handler', 'phpbb_user_session_handler', 'append_sid', array('template', 'display')));
  227.  
  228. foreach ($cache->obtain_hooks() as $hook)
  229. {
  230. @include($phpbb_root_path . 'includes/hooks/' . $hook . '.' . $phpEx);
  231. }
  232.  
  233. ?>
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.