1 (edited by Paul 2004-02-09 20:56)

Topic: Extern Problems

I and at least one other have been having difficulties with extern.php.

1. Could somebody explain why problems might arise when trying to include extern.php using a relative path rather than a url. The idea is to duplicate what the punbb site does on the front page with recent posts

2. Is there any reason why it should be a problem including extern.php inside a file which is itself an include in another file. Here is what JohnS posted specific to his problem

The right hand column on my site is an include (xtc_right_bar.php).
Within this I've placed another include calling forum/extern.php

I get a list of topics displayed but with the following error message
above them...

Warning: main(): stream does not support seeking
in /includes/xtc_right_bar.php on line 44

Should I be calling the full url of extern.php or just its relative path or is
the problem with having an include within an include?

Any help appreciated

Re: Extern Problems

Might I ask if you have Zend Optimizer installed? The reason I ask is this.

"Programming is like sex: one mistake and you have to support it for the rest of your life."

3 (edited by Paul 2004-02-09 21:52)

Re: Extern Problems

I am not sure, phpinfo says something about zend extension and shows this

This program makes use of the Zend Scripting Language Engine:
Zend Engine v1.3.0, Copyright (c) 1998-2003 Zend Technologies

Is that what you mean. I can use extern perfectly provided I use the url rather than a relative (or absolute) address. Strangely, I did get it working once with a relative address by using require instead of include.

JohnS I think has a slightly different problem because he has trouble even with url's.

EDIT

Read the article you referred to. using @include resolves  the problems when using a url but it doesn't help with relative addressing and I don't really want to have to use a url to include a local file.

4

Re: Extern Problems

Copied from the topic I started in Show Offs...

I've tried full url, absolute path and relative path but all with errors.

The include I use for right margin is in a directory htdocs/includes/
and my forum is in a directory htdocs/forum/

Because right margin is included into root files the relative path I specify is forum/extern.php

So confusing!

I've been down so long it's beginning to look like up..

Re: Extern Problems

Paul: The Zend Engine is something different from Zend Optimizer.

JohnS: If it can't find the file at all, you would get a different error message, so the path is most likely correct.

What PHP versions are you using?

Here's how to check if Zend Optimizer is running.

"Programming is like sex: one mistake and you have to support it for the rest of your life."

6

Re: Extern Problems

In that case no, nothing in phpinfo refers to the Zend Optimizer.

Re: Extern Problems

In that case, I really have no idea what might be wrong. I very much doubt it's a bug in PunBB. Have you tried googling and trying out some possible solutions from the search results?

"Programming is like sex: one mistake and you have to support it for the rest of your life."

8

Re: Extern Problems

In that case, could you refresh my memory on how you are showing recent posts on your front page. Are you using extern.php? Could you show the code if it's not too much trouble.

Re: Extern Problems

I don't use extern.php, because I need access to $cur_user['style'] to be able to show the same style on the site as in the forums.

Here's some code:

<?php

define('PUN_TURN_OFF_MAINT', 1);
define('PUN_QUIET_VISIT', 1);

$pun_root = '../forums/';
@include $pun_root.'include/common.php';

// If PUN isn't defined, config.php is missing or corrupt
if (!defined('PUN'))
    exit('config.php doesn\'t exist or is corrupt. Please run install.php to install PunBB first.');

?>

And then the topic list:

<?php

$result = $db->query('SELECT t.id, t.subject FROM '.$db->prefix.'topics AS t,'.$db->prefix.'forums AS f WHERE t.forum_id=f.id AND f.admmod_only=0 AND t.moved_to IS NULL ORDER BY t.last_post LIMIT 15') or error('Unable to fetch topic list', __FILE__, __LINE__, $db->error());

while ($cur_topic = $db->fetch_assoc($result))
{
    if ($pun_config['o_censoring'] == '1')
        $cur_topic['subject'] = censor_words($cur_topic['subject']);

    if (pun_strlen($cur_topic['subject']) > 30)
        $cur_topic['subject'] = trim(substr($cur_topic['subject'], 0, 24)).' ...';

    echo "\t\t\t\t\t\t\t".'<b>·</b> <a href="http://punbb.org/forums/viewtopic.php?id='.$cur_topic['id'].'">'.pun_htmlspecialchars($cur_topic['subject']).'</a><br>'."\n";
}

?>
"Programming is like sex: one mistake and you have to support it for the rest of your life."

10

Re: Extern Problems

Wonderful. Thanks for that.

while (braindead)
{
    pester_rickard();
}

11

Re: Extern Problems

Rickard wrote:

JohnS: If it can't find the file at all, you would get a different error message, so the path is most likely correct.

What PHP versions are you using?

Zend Engine V.1.3.0
Zend Optimizer V.2.1.0
PHP V.4.3.2

BTW: I've used @include with the full url (as Paul suggested) and it now works fine but it does seem strange why I can't just use a relative path...

I've more chance of understanding Swedish than coding :x

I've been down so long it's beginning to look like up..

12 (edited by Louis 2004-02-10 21:22)

Re: Extern Problems

Guys, please. RTFM ;)

Specifically, look at the code sample and you'll realise why it doesn't work:

PHP Manual on Include():

If "URL fopen wrappers" are enabled in PHP (which they are in the default configuration), you can specify the file to be included using a URL (via HTTP or other supported wrapper - see Appendix J for a list of protocols) instead of a local pathname. If the target server interprets the target file as PHP code, variables may be passed to the included file using a URL request string as used with HTTP GET. This is not strictly speaking the same thing as including the file and having it inherit the parent file's variable scope; the script is actually being run on the remote server and the result is then being included into the local script.

Warning
Windows versions of PHP prior to PHP 4.3.0 do not support accessing remote files via this function, even if allow_url_fopen is enabled.

<?php

/* This example assumes that www.example.com is configured to parse .php
 * files and not .txt files. Also, 'Works' here means that the variables
 * $foo and $bar are available within the included file. */

// Won't work; file.txt wasn't handled by www.example.com as PHP
include 'http://www.example.com/file.txt?foo=1&bar=2';

// Won't work; looks for a file named 'file.php?foo=1&bar=2' on the
// local filesystem.
include 'file.php?foo=1&bar=2';

// Works.
include 'http://www.example.com/file.php?foo=1&bar=2';

$foo = 1;
$bar = 2;
include 'file.txt';  // Works.
include 'file.php';  // Works.

?> 

Definitely read that entire page, just to make sure you haven't missed anything.

Next time, test it first Rickard! ;)

Spot.

13

Re: Extern Problems

Oh, My God!
I've more chance of learning Russian, Chinese, etc. etc. ...

So. What do I do? Keep using @include?

I've been down so long it's beginning to look like up..

Re: Extern Problems

Louis: I'm sorry, but I just can't see what is so obvious to you. It has nothing to do with "URL fopen wrappers" if that's what you meant. Trying to include a file via an URL when URL fopen wrappers are disabled leads to a different error message.

"Programming is like sex: one mistake and you have to support it for the rest of your life."

15 (edited by Paul 2004-02-11 00:17)

Re: Extern Problems

JohnS wrote:

Oh, My God!
So. What do I do? Keep using @include?

Either that or forget extern and use the code Rickard posted. I will give that a shot and seen what happens. I will let you know. Of course, you could use SSI in the form of the examples given.

One final thing I am going to try is to make a modified version of extern that does not require parameters. The idea it to turn the relevant parts of extern into functions which can be called using parameters after it has been included using a local address. That way it would be possible to include active topics and newest topics etc on the same page with only one include, I think.

[EDIT] Rant deleted. I get it smile

16 (edited by Louis 2004-02-11 01:05)

Re: Extern Problems

Rickard wrote:

Louis: I'm sorry, but I just can't see what is so obvious to you. It has nothing to do with "URL fopen wrappers" if that's what you meant. Trying to include a file via an URL when URL fopen wrappers are disabled leads to a different error message.

No, I meant this:

// Won't work; looks for a file named 'file.php?foo=1&bar=2' on the
// local filesystem.
include 'file.php?foo=1&bar=2';

When you include for the -- err, ahh ... never mind. Note to self: Don't post when you're tired, you'll only make mistakes.

17 (edited by Paul 2004-02-11 02:36)

Re: Extern Problems

It's OK Louis. I got it. Nobody told me that there were problems passing parameters/arguments using a local address. I have now made a new version of extern.php which is externlocal.php which includes a function called show_pun. To use it locally I can just do this

include('../punbb/externlocal.php');
show_pun('active',12);
show_pun('new', 5);
show_pun('online');
show_pun('stats');

The only benefits of doing it this way is that local addresses can be used and if you want to show several bits of information from PunBB you only have to include the file once. If you only want to show active topics then Rickards PunBB.org code would seem to be neater.

Note to self. File can be simplified; why would anybody want to use an RSS feed on the same site that houses the forum.

JohnS. This could be the neatest solution for you. I will post the file as soon as I have finished tinkering.

18

Re: Extern Problems

Paul, the externlocal.php file, is there somewhere where I can download it?

Is extern.php changing for 1.2?

19

Re: Extern Problems

hcgtv wrote:

Paul, the externlocal.php file, is there somewhere where I can download it?

Sorry, I stopped using extern so the file went to silicon heaven a long time ago.