Topic: PHP: include

hi all.  i'm attempting to write up a bittorrent tracker module for PunBB but i'm new at this stuff.  i have one page that displays torrent info from the database, called puntracker.php.  but i have another page called punscrape.php that scrapes other trackers and updates mysql.  so my newb question is what's the best way to do this?  can i just put
include(PUN_ROOT.'punscrape.php');
or something similar to evaluate the file or is this stupid?  thanks for any tips.

Re: PHP: include

ok, on my index page i include my scraper page.  on my index page i instantiate the scraper object on my scraper page.  but i get this error.

[08-May-2007 20:33:08] PHP Fatal error:  Cannot redeclare check_cookie() (previously declared in /testforum/include/functions.php:28) in /testforum/include/functions.php on line 28

any tips for a newb?

thanks.

Re: PHP: include

Are you including common.php on both pages? If so, that's your issue

4 (edited by eric235u 2007-05-08 20:58)

Re: PHP: include

yep i'm including common.php on both pages.  so if i can't do that, how can i use the database object in my 'scraper' page?  when i remove common.php i get

PHP Fatal error:  Call to a member function on a non-object in /testforum/punscrape.php on line 31

which is right where i use $db

do i use something else like include common_db.php?

thanks a ton for any assistance.  i almost have a bittorrent tracker module ready but i'm banging my head on this last part.  it's turned out to be a little harder than i expected!

5 (edited by eric235u 2007-05-11 18:30)

Re: PHP: include

i'm currently reading more about objects.  forgive my newbian questions.  my little object doesn't have access to $db...

define('PUN_ROOT', './');
require PUN_ROOT.'include/common.php';
define('PUN_ALLOW_INDEX', 1);
require PUN_ROOT.'header.php';

// the scrape object
class punscrape
{
    function do_scrape()
    {

// let's check if the torrent(s) need to be scraped.
$table = $db->prefix('puntracker');
...

it gives me call to a member function on a non-object.  it seems i need to learn about scope???  anybody got a good link to some literature to help?  tia.

Re: PHP: include

Your problem is that you need to declare a variable global at the start of every function. Even in classes. So put
global $db;
as the first line of your function and it'll work.

Re: PHP: include

ha, that works!  thanks man.

1 bug down, 4 million to go.