Op mijn homepage wil ik dmv de volgende php include de meest recente topics van mijn phpBB forum weergeven:
In dit php bestand gebeurt het volgende:
Wanneer ik dit bestand include krijg ik de melding:
Door die setcookie worden er blijkbaar headers meegestuurd.
Probleemoorzaak is dus bekend. Ik heb alleen geen idee hoe ik moet voorkomen!
Output buffering (ob_start(); gebruiken) heb ik geprobeerd, maar dat hielp niet.
Hoe kan ik ervoor zorgen dat die setcookie aangeroepen wordt voordat er door de geinclude php file output naar mijn webpagina gestuurd wordt?
sessions.php is overigens een standaard bestand van mijn phpBB forum en daar wil ik liever niet in rommelen als dat niet nodig is, want mijn kennis van php is beperkt en ik wil niet dat mijn forum straks niet meer werkt
Alvast bedankt voor de hulp!
PHP:
1
| <?php include("forum/mods/phpbb_fetch_all/include_latestpostings.php");?> |
In dit php bestand gebeurt het volgende:
PHP:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
| <?php // // This path points to the directory where phpBB is installed. Do // not enter an URL here. The path must end with a trailing // slash. // // Examples: // forum in /aaa/bbb/ccc/ and script in /aaa/bbb/ccc/ // --> $phpbb_root_path = './'; // forum in /aaa/bbb/ccc/ and script in /aaa/bbb/ // --> $phpbb_root_path = './ccc/'; // forum in /aaa/bbb/ccc/ and script in /aaa/bbb/ddd/ // --> $phpbb_root_path = '../ccc/'; // $phpbb_root_path = 'forum/'; define ('IN_PHPBB', true); if (!file_exists($phpbb_root_path . 'extension.inc')) { die ('<tt><strong>phpBB Fetch All:</strong> $phpbb_root_path is wrong and does not point to your forum.</tt>'); } // // phpBB related files // include_once ($phpbb_root_path . 'extension.inc'); include_once ($phpbb_root_path . 'common.' . $phpEx); include_once ($phpbb_root_path . 'includes/bbcode.' . $phpEx); // // Fetch All related files - we do need all these because the portal is a // huge example // include_once ($phpbb_root_path . 'mods/phpbb_fetch_all/common.' . $phpEx); include_once ($phpbb_root_path . 'mods/phpbb_fetch_all/posts.' . $phpEx); // // start session management // $userdata = session_pagestart($user_ip, PAGE_INDEX); init_userprefs($userdata); // // since we are demonstrating span pages we need to set the page offset // if (isset($HTTP_GET_VARS['start']) or isset($HTTP_POST_VARS['start'])) { $CFG['posts_span_pages_offset'] = isset($HTTP_GET_VARS['start']) ? $HTTP_GET_VARS['start'] : $HTTP_POST_VARS['start']; if (!intval($CFG['posts_span_pages_offset'])) { $CFG['posts_span_pages_offset'] = 0; } if (!is_numeric($CFG['posts_span_pages_offset'])) { $CFG['posts_span_pages_offset'] = 0; } if ($CFG['posts_span_pages_offset'] < 0) { $CFG['posts_span_pages_offset'] = 0; } } // fetch latest postings $CFG['posts_trim_topic_number'] = 60; $recent = phpbb_fetch_posts(null, POSTS_FETCH_LAST); // // disconnect from the database // phpbb_disconnect(); ?> <?php if (isset($recent)) { ?> <?php for ($i = 0; $i < count($recent); $i++) { ?> <?php echo '<span class="latesttopics_date">';?> <?php echo create_date($board_config['default_dateformat'], $recent[$i]['post_time'], $board_config['board_timezone']); ?> <?php echo '</span>';?> <?php echo '<span class="latesttopics_topic">';?> <?php echo ':<br /><img src="http://www.alice-in-wonderland.net/layoutpics/topicarrow.gif" border="0" align="absmiddle" /> <a target="_blank" href="';?> <?php echo append_sid($phpbb_root_path . 'viewtopic.php?p=' . $recent[$i]['post_id'] . '#' . $recent[$i]['post_id']); ?> <?php echo '">';?> <?php echo $recent[$i]['topic_title']; ?> <?php if ($recent[$i]['topic_trimmed']) { echo '...'; } ?> <?php echo '</a><br />';?> <?php echo '</span>';?> <?php } ?> <?php } ?> |
Wanneer ik dit bestand include krijg ik de melding:
Ik weet wat de oorzaak is van deze melding. Het ligt niet aan spaties e.d. die buiten de php-code vallen, maar het komt doordat in het bestand dat ge-include wordt, er naar sessions.php verwezen wordt, waarin op de regels van de fout de volgende code wordt aangeroepen:Warning: Cannot modify header information - headers already sent by (output started at /home/aliceinw/public_html/test.html:11) in /home/aliceinw/public_html/forum/includes/sessions.php on line 367
Warning: Cannot modify header information - headers already sent by (output started at /home/aliceinw/public_html/test.html:11) in /home/aliceinw/public_html/forum/includes/sessions.php on line 368
PHP:
1
2
| setcookie($cookiename . '_data', serialize($sessiondata), $current_time + 31536000, $cookiepath, $cookiedomain, $cookiesecure); setcookie($cookiename . '_sid', $session_id, 0, $cookiepath, $cookiedomain, $cookiesecure); |
Door die setcookie worden er blijkbaar headers meegestuurd.
Probleemoorzaak is dus bekend. Ik heb alleen geen idee hoe ik moet voorkomen!
Output buffering (ob_start(); gebruiken) heb ik geprobeerd, maar dat hielp niet.
Hoe kan ik ervoor zorgen dat die setcookie aangeroepen wordt voordat er door de geinclude php file output naar mijn webpagina gestuurd wordt?
sessions.php is overigens een standaard bestand van mijn phpBB forum en daar wil ik liever niet in rommelen als dat niet nodig is, want mijn kennis van php is beperkt en ik wil niet dat mijn forum straks niet meer werkt
Alvast bedankt voor de hulp!