php include help

Can't get it installed? Not sure how a feature works? Then post here.

php include help

Postby jaylam » 2011-01-23 04:27 pm

Hi,

I am trying to include a php file to the wrapper using
Code: Select all
{include "../featured.php"}


which works perfectly, it does include that file but instead of running the script in that php file to display content it just prints the code in that file.

Anyone know what im doing wrong?

Thanks in advance.

Jay
jaylam
Newbie
 
Posts: 9
Joined: 2011-01-23 04:24 pm

Re: php include help

Postby jaylam » 2011-01-24 05:30 am

Anyone got any suggestions?
jaylam
Newbie
 
Posts: 9
Joined: 2011-01-23 04:24 pm

Re: php include help

Postby Basti » 2011-01-24 09:04 am

Most likely the code from featured.php is wrong, would help seeing it
Basti
Advanced Member
 
Posts: 1619
Joined: 2004-06-20 06:17 pm
Location: Germany

Re: php include help

Postby jaylam » 2011-01-24 09:17 am

Basti wrote:Most likely the code from featured.php is wrong, would help seeing it


Featured.php is just a script to pull a topic out of my phpbb forum, it works everywhere else on the site and if I go directly to http://www.my_domain.com/topsites/skins ... apper.html it then includes the file just not when I go via the index.php in the root of the topsites folder.

The code for featured.php is:
Code: Select all
<?php
define('PRINT_TO_SCREEN', true);         
define('IN_PHPBB', true);
$phpbb_root_path = "forums/";
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);
include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
include($phpbb_root_path . 'includes/bbcode.' . $phpEx);
$user->session_begin(false);
$auth->acl($user->data);
$user->setup();
include_once($path.$config_path .'forums/config.php');
mysql_connect('localhost', ******', ******') OR die('Unable to select server.');
mysql_select_db('******') OR die('Unable to select database.');

//////////////////////////////////////
//

define('FORUM_ID', 44);                    // Forum ID to get data from
define('POST_LIMIT', 1);                  // How many to get
define('PHPBB_ROOT_PATH', 'forums/');   // Path to phpBB (including trailing /)

define('PRINT_TO_SCREEN', true);         


$query =
"SELECT u.user_id, u.username, t.topic_title, t.topic_poster, t.forum_id, t.topic_id, t.topic_time, t.topic_replies, t.topic_first_post_id, p.poster_id, p.topic_id, p.post_id, p.post_text, p.bbcode_bitfield, p.bbcode_uid
FROM ".USERS_TABLE." u, ".TOPICS_TABLE." t, ".POSTS_TABLE." p
WHERE u.user_id = t.topic_poster
AND u.user_id = p.poster_id
AND t.topic_id = p.topic_id
AND p.post_id = t.topic_first_post_id
AND t.forum_id = 44
ORDER BY RAND()";

$result = $db->sql_query_limit($query, 1);
$posts = array();
$news = array();
$bbcode_bitfield = '';
$message = '';
$poster_id = 0;

while ($r = $db->sql_fetchrow($result))
{
   $posts[] = array(
         'topic_id' => $r['topic_id'],
         'topic_time' => $r['topic_time'],
         'username' => $r['username'],
         'topic_title' => $r['topic_title'],
         'post_text' => $r['post_text'],
         'bbcode_uid' => $r['bbcode_uid'],
         'bbcode_bitfield' => $r['bbcode_bitfield'],
         'topic_replies' => $r['topic_replies'],
         );
   $bbcode_bitfield = $bbcode_bitfield | base64_decode($r['bbcode_bitfield']);
}


// Instantiate BBCode
if ($bbcode_bitfield !== '')
{
   $bbcode = new bbcode(base64_encode($bbcode_bitfield));
}

// Output the posts
foreach($posts as $m)
{
   $poster_id = $m['user_id'];
   
   $message = $m['post_text'];
   if($m['bbcode_bitfield'])
   {
      $bbcode->bbcode_second_pass($message, $m['bbcode_uid'], $m['bbcode_bitfield']);
   }

   $message = str_replace("\n", '<br />', $message);
   $message = smiley_text($message);

   $comment = ($m['topic_replies']==1) ? 'comment' : 'comments';
   
   if( PRINT_TO_SCREEN )
   {
     

      echo "\n{$message}";
      echo "<br>";
     
   }
   else
   {
      $news[] = array(
            'topic_id' => $m['topic_id'], // eg: 119
           
            'topic_time' => $user->format_date($m['topic_time']), // eg: 06 June, 07 (uses board default)
            'topic_replies' => $m['topic_replies'], // eg: 26
           
            'username' => $m['username'], // eg: chAos
            'topic_title' => $m['topic_title'], // eg: "News Post"
           
            'post_text' => $message, // just the text         
            );
   }
   
   unset($message,$poster_id);
}

?>
<body>
</body>
jaylam
Newbie
 
Posts: 9
Joined: 2011-01-23 04:24 pm

Re: php include help

Postby Basti » 2011-01-24 09:44 am

I see, very odd actually. I just gave the a include a test on my site and its works as espected, so something must be wrong within your included file.

can you pls try to remove the body html tags from that file at the bottom?
It should make your site invalid, hopefully its just that why it aint work
Basti
Advanced Member
 
Posts: 1619
Joined: 2004-06-20 06:17 pm
Location: Germany

Re: php include help

Postby jaylam » 2011-01-24 09:53 am

Basti wrote:I see, very odd actually. I just gave the a include a test on my site and its works as espected, so something must be wrong within your included file.

can you pls try to remove the body html tags from that file at the bottom?
It should make your site invalid, hopefully its just that why it aint work


Its just strange that it works when I go directly to wrapper.html but not when I go to it via the index.php file in the topsites folder thats why I dont think its the included file as it would not work with either if it was wrong.

Just tried removing the tags as requested, still doesnt work :(
jaylam
Newbie
 
Posts: 9
Joined: 2011-01-23 04:24 pm

Re: php include help

Postby Basti » 2011-01-24 10:17 am

Do you have the site url with the problem intact? would like to see this for myself

pm me if you do not wish to make it public
Basti
Advanced Member
 
Posts: 1619
Joined: 2004-06-20 06:17 pm
Location: Germany

Re: php include help

Postby jaylam » 2011-01-24 10:19 am

Basti wrote:Do you have the site url with the problem intact? would like to see this for myself

pm me if you do not wish to make it public


No disrespect meant but I would rather not as the include file it is printing instead of running is showing db usernames, passwords etc :(

Is there anything you want me to try?
jaylam
Newbie
 
Posts: 9
Joined: 2011-01-23 04:24 pm

Re: php include help

Postby Basti » 2011-01-24 10:27 am

Ok, no problem.

So we need to spot the problems one by one.

The first thing we need to confirm is if your included file is the issue or not.
For that replace the hole content with
Code: Select all
<?php echo 'Hello World'; ?>


If that get printed correctly we can be sure, its your file. If not it can be either the include callin wrapper or some serverside issue.
Basti
Advanced Member
 
Posts: 1619
Joined: 2004-06-20 06:17 pm
Location: Germany

Re: php include help

Postby jaylam » 2011-01-24 10:36 am

Basti wrote:Ok, no problem.

So we need to spot the problems one by one.

The first thing we need to confirm is if your included file is the issue or not.
For that replace the hole content with
Code: Select all
<?php echo 'Hello World'; ?>


If that get printed correctly we can be sure, its your file. If not it can be either the include callin wrapper or some serverside issue.


Thanks, ok done that and now it just includes nothing just a white space where the include should be.
jaylam
Newbie
 
Posts: 9
Joined: 2011-01-23 04:24 pm

Re: php include help

Postby Basti » 2011-01-24 10:43 am

Ok so, the next try. keep the echo in the php file, we keep that until we get it to show

Change your include to full path

to
Code: Select all
{include "http://www.site.com/topsites/featured.php"}


Also do you have msn or skype? would make the error spotting faster
Basti
Advanced Member
 
Posts: 1619
Joined: 2004-06-20 06:17 pm
Location: Germany

Re: php include help

Postby jaylam » 2011-01-24 10:49 am

Basti wrote:Ok so, the next try. keep the echo in the php file, we keep that until we get it to show

Change your include to full path

to
Code: Select all
{include "http://www.site.com/topsites/featured.php"}


Also do you have msn or skype? would make the error spotting faster


ok that worked *confused*

yes my msn is lambertj13[AT]gmail[DOT]com
jaylam
Newbie
 
Posts: 9
Joined: 2011-01-23 04:24 pm

Re: php include help

Postby Basti » 2011-01-24 10:51 am

Ok change your included file baack to your forum stuff, hopefully it work now as well
Basti
Advanced Member
 
Posts: 1619
Joined: 2004-06-20 06:17 pm
Location: Germany

Re: php include help

Postby jaylam » 2011-01-24 11:01 am

Basti wrote:Ok change your included file baack to your forum stuff, hopefully it work now as well


Yep that works thanks a lot for helping me out I appreciate it.

Why does it work with the full address but not using the ../filename.php way?
jaylam
Newbie
 
Posts: 9
Joined: 2011-01-23 04:24 pm

Re: php include help

Postby Basti » 2011-01-24 11:22 am

Not exactly sure to be honest, but i bet some server config issue which prevent using relative paths like you did. Cant say for sure though, since i always avoid using relative paths
Basti
Advanced Member
 
Posts: 1619
Joined: 2004-06-20 06:17 pm
Location: Germany

Next

Return to Support

Who is online

Users browsing this forum: No registered users and 0 guests

cron