Results 1 to 4 of 4

Thread: [RESOLVED] Linking a PHP page to another

  1. #1

    Thread Starter
    PowerPoster kfcSmitty's Avatar
    Join Date
    May 2005
    Posts
    2,248

    Resolved [RESOLVED] Linking a PHP page to another

    *edit* ehhh...for some reason if it loads once, i get the errors...If i load it a 2nd time, it works fine...


    I am using a script from smartor.is-root.com to link my phpBB forum and display certain news articles on another page. This works as long as the page is located in the forum folder, but I want it to link to my main page.

    basically, I want the page to look like

    http://www.dragonzbp.com/DragonzForum/index2.php

    but it gives me errors if i try it outside the forum directory.

    here is what i get

    www.dragonzbp.com

    I don't know how to fix the erroirs and its really bugging me :/

    here is the code:

    Code:
    <?php
    /***************************************************************************
     *                                portal.php
     *                            -------------------
     *   begin                : Tuesday, August 13, 2002
     *   copyright            : (C) 2002 Smartor
     *   email                : [email protected]
     *
     *   $Id: portal.php,v 2.1.7 2003/01/30, 17:05:58 Smartor Exp $
     *
     ***************************************************************************/
    
    /***************************************************************************
     *
     *   This program is free software; you can redistribute it and/or modify
     *   it under the terms of the GNU General Public License as published by
     *   the Free Software Foundation; either version 2 of the License, or
     *   (at your option) any later version.
     *
     ***************************************************************************/
    
    /***************************************************************************
     *
     *   Some code in this file I borrowed from the original index.php, Welcome
     *   Avatar MOD and others...
     *
     ***************************************************************************/
    
    //
    // Set configuration for ezPortal
    //
    
    // Welcome Text: note that we are in PHP file, so use \' instead of ' and use \\ instead of \ (HTML enabled)
    $CFG['welcome_text'] = 'Welcome to <b>My Community</b><br /><br />Thanks for using ezPortal,<br /><br />Have a good time! ^_^';
    
    // Number of news on portal
    $CFG['number_of_news'] = '5';
    
    // Length of news
    $CFG['news_length'] = '800';
    
    // News Forum ID: separate by comma for multi-forums, eg. '1'
    $CFG['news_forum'] = '1';
    
    // Poll Forum ID: separate by comma for multi-forums, eg. '3,8,14'
    $CFG['poll_forum'] = '1';
    
    //
    // END configuration
    // --------------------------------------------------------
    
    define('IN_PHPBB', true);
    /////////////////////////////////////////////////
    $phpbb_root_path = './DragonzForum/';
    include($phpbb_root_path . 'extension.inc');
    include($phpbb_root_path . 'common.'.$phpEx);
    include($phpbb_root_path . 'fetchposts.'.$phpEx);
    
    //
    // Start session management
    //
    $userdata = session_pagestart($user_ip, PAGE_INDEX);
    init_userprefs($userdata);
    //
    // End session management
    //
    
    
    $template->set_filenames(array(
    	'body' => 'portal_body.tpl')
    );
    
    
    $template->assign_vars(array(
    	'WELCOME_TEXT' => $CFG['welcome_text'],
    	'TOTAL_POSTS' => sprintf($l_total_post_s, $total_posts),
    	'TOTAL_USERS' => sprintf($l_total_user_s, $total_users),
    	'TOTAL_TOPICS' => sprintf($lang['total_topics'], $total_topics),
    	'NEWEST_USER' => sprintf($lang['Newest_user'], '<a href="' . append_sid("profile.$phpEx?mode=viewprofile&amp;" . POST_USERS_URL . "=$newest_uid") . '">', $newest_user, '</a>'),
    	'L_FORUM' => $lang['Forum'],
    	'L_BOARD_NAVIGATION' => $lang['Board_navigation'],
    	'L_STATISTICS' => $lang['Statistics'],	
    	'L_ANNOUNCEMENT' => $lang['Post_Announcement'],
    	'L_POSTED' => $lang['Posted'],
    	'L_COMMENTS' => $lang['Comments'],
    	'L_VIEW_COMMENTS' => $lang['View_comments'],
    	'L_POST_COMMENT' => $lang['Post_your_comment'],
    	'L_SEND_PASSWORD' => $lang['Forgotten_password'],
    	'U_SEND_PASSWORD' => append_sid("profile.$phpEx?mode=sendpassword"),
    	'L_REGISTER_NEW_ACCOUNT' => sprintf($lang['Register_new_account'], '<a href="' . append_sid("profile.$phpEx?mode=register") . '">', '</a>'),
    	'L_REMEMBER_ME' => $lang['Remember_me'],
    	'L_VIEW_COMPLETE_LIST' => $lang['View_complete_list'],
    	'L_POLL' => $lang['Poll'],
    	'L_VOTE_BUTTON' => $lang['Vote'],
    
    	// Welcome Avatar
    	'L_NAME_WELCOME' => $lang['Welcome'],
    	'U_NAME_LINK' => $name_link,
    	'AVATAR_IMG' => $avatar_img)
    );
    
    //
    // Fetch Posts from Announcements Forum
    //
    if(!isset($HTTP_GET_VARS['article']))
    {
    	$template->assign_block_vars('welcome_text', array());
    
    	$fetchposts = phpbb_fetch_posts($CFG['news_forum'], $CFG['number_of_news'], $CFG['news_length']);
    
    	for ($i = 0; $i < count($fetchposts); $i++)
    	{
    		if( $fetchposts[$i]['striped'] == 1 )
    		{
    			$open_bracket = '[ ';
    			$close_bracket = ' ]';
    			$read_full = $lang['Read_Full'];
    		}
    		else
    		{
    			$open_bracket = '';
    			$close_bracket = '';
    			$read_full = '';
    		}
    
    		$template->assign_block_vars('fetchpost_row', array(
    			'TITLE' => $fetchposts[$i]['topic_title'],
    			'POSTER' => $fetchposts[$i]['username'],
    			'TIME' => $fetchposts[$i]['topic_time'],
    			'TEXT' => $fetchposts[$i]['post_text'],
    			'REPLIES' => $fetchposts[$i]['topic_replies'],
    			'U_VIEW_COMMENTS' => append_sid('viewtopic.' . $phpEx . '?t=' . $fetchposts[$i]['topic_id']),
    			'U_POST_COMMENT' => append_sid('posting.' . $phpEx . '?mode=reply&amp;t=' . $fetchposts[$i]['topic_id']),
    			'U_READ_FULL' => append_sid('portal.' . $phpEx . '?article=' . $i),
    			'L_READ_FULL' => $read_full,
    			'OPEN' => $open_bracket,
    			'CLOSE' => $close_bracket)
    		);
    	}
    }
    else
    {
    	$fetchposts = phpbb_fetch_posts($CFG['news_forum'], $CFG['number_of_news'], 0);
    
    	$i = intval($HTTP_GET_VARS['article']);
    
    	$template->assign_block_vars('fetchpost_row', array(
    		'TITLE' => $fetchposts[$i]['topic_title'],
    		'POSTER' => $fetchposts[$i]['username'],
    		'TIME' => $fetchposts[$i]['topic_time'],
    		'TEXT' => $fetchposts[$i]['post_text'],
    		'REPLIES' => $fetchposts[$i]['topic_replies'],
    		'U_VIEW_COMMENTS' => append_sid('viewtopic.' . $phpEx . '?t=' . $fetchposts[$i]['topic_id']),
    		'U_POST_COMMENT' => append_sid('posting.' . $phpEx . '?mode=reply&amp;t=' . $fetchposts[$i]['topic_id'])
    		)
    	);
    }
    //
    // END: Fetch Announcements
    //
    
    //
    // Generate the page
    //
    $template->pparse('body');
    
    
    ?>
    I kinda suck with PHP, but I managed to get this script working on another site, I just can't remember how

    Any help would be appreciated

  2. #2
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: Linking a PHP page to another

    The errors you are getting are cuased becuase PHP is strying to send a header (probably cookies). However, somewhere in your script the output has already started meaning the no more headers can be set.

    Make sure there is no whitespace before the first opening php tag on the first line of the script, if there is, delete it.
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  3. #3

    Thread Starter
    PowerPoster kfcSmitty's Avatar
    Join Date
    May 2005
    Posts
    2,248

    Re: Linking a PHP page to another

    Thanks for the tip...I have removed all the white space from the opening <? and the startof the script. However, the error persists....If i log onto the forum I am linking to and then go to the site, I get no errors... It's strange.

    Could it be because i am using css on the main webpage, and then placing the template css from another file on the main page as well when I insert the php?

    Sorry for the bad wording..I am kinda tired atm


    *edit* I went through sessions.php and removed the cookie saving...so now the error is no longer coming up..Thanks for your help
    Last edited by kfcSmitty; Jan 26th, 2006 at 01:23 AM.

  4. #4
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: [RESOLVED] Linking a PHP page to another

    It is exactly because of what you said. Sessions require a cookie and the cookie is set using an HTTP header. As the name suggests, headers are at the head of an HTTP response and sould therefore be sent first:

    HTTP Reponse
    Code:
    HTTP/1.1 200 OK
    Cookie: cookiename=cookievalue
    Server: Apache/2.0
    
    
    <html>
      <body>
      ...
      </body>
    </html>
    If PHP has already started sending the request body and youi attempt to send a header, it will not work.

    I would advise you keep the session handling code and at the top of the main index page add a line which starts an output buffer. The output buffer will cause all output to be collected until the script is finished, meaning that you can send the headers at any time.
    PHP Code:
    <?php ob_start(); ?>
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width