Author Topic: Trouble with PHP include  (Read 6747 times)

0 Members and 1 Guest are viewing this topic.

Offline wildbill

  • Pre-Newbie
  • Posts: 6
    • View Profile
Trouble with PHP include
« on: May 24, 2002, 05:07:51 AM »
Hello,

Sorry I don't speak German...

I am trying to add a php include in my header.html template.  I have tried to put the include in both the "includes" folder within the root of 4images and outside of the root as well.  No matter what happens, I get an error and my page won't load.

Any known issues with including code in the header such as
<?php
  include('http://mysite.com/phpincludes/active_users.class.php');
  $au = new activeUsers;
echo $au->numActive();
?>

When I add this in my header.html, the whole photo gallery crashes.

Any ideas?

Offline jose

  • Pre-Newbie
  • Posts: 5
    • View Profile
Trouble with PHP include
« Reply #1 on: May 24, 2002, 08:31:11 AM »
I did it yesterday... with the same class:
include the class into a common php (b.e. config.php)
Code: [Select]
include('http://mysite.com/phpincludes/active_users.class.php');
$au = new activeUsers;

Then make a new template variable {U_ONLINE}, put into a template.
Then in page_header.php addd in
Code: [Select]
$site_template->register_vars(array("media_url" => MEDIA_PATH,something like :
Code: [Select]
"u_online" => $au-> numActive(),
Thats all[/code]

Offline wildbill

  • Pre-Newbie
  • Posts: 6
    • View Profile
Trouble with PHP include
« Reply #2 on: May 24, 2002, 12:03:26 PM »
Thanks, Jose, for your response...I haven't gotten it quite yet, however.

Here's what I've done...

I added this into config.php

Code: [Select]
include('http://mysite.com/phpincludes/active_users.class.php');
$au = new activeUsers;


In page_header.php, I added this at the very bottom. I think there may be a syntax error at the end?

Code: [Select]
$site_template->register_vars(array("u_online" => $au-> numActive(),));

Then, in footer.html, I added the variable
Code: [Select]
{u_online}

Then I tried it and it freaked out. Something like this pops up

Fatal error: Cannot instantiate non-existent class: activeusers in /home/www/mysite/gallery/config.php on line 27

Where am I going wrong?

Offline jose

  • Pre-Newbie
  • Posts: 5
    • View Profile
Trouble with PHP include
« Reply #3 on: May 24, 2002, 12:21:12 PM »
Try something like this in page_header.php:
Code: [Select]

include('./includes/active_users.class.php');
$au = new activeUsers;
$users_online = $au->numActive(); //number of users online

$site_template->register_vars(array("media_url" => MEDIA_PATH,
"thumb_url" => THUMB_PATH,
...
"url_member" => $site_sess->url("member.php"),
"u_online" => $users_online,
"url_lost_password" => $site_sess->url("member.php?action=lostpassword")
));
[/code]

Offline wildbill

  • Pre-Newbie
  • Posts: 6
    • View Profile
Lost everything with the first method...I fixed it though
« Reply #4 on: May 24, 2002, 01:09:16 PM »
Thank god for backing up the database...that first method you gave me brought me back to an install screen...

Ok Jose, regarding the latest code you gave me...do I need ALL OF IT or just the top portion?  

Code: [Select]
include('./includes/active_users.class.php');
$au = new activeUsers;
$users_online = $au->numActive(); //number of users online


I see that pesky
Code: [Select]
"u_online" => $users_online, snippet in there.  I keep getting errors everytime I try this.  I'm close, though, I can feel it...

My active_users.class.php sits outside of the photo gallery root.  Does this matter?

Offline jose

  • Pre-Newbie
  • Posts: 5
    • View Profile
Trouble with PHP include
« Reply #5 on: May 24, 2002, 01:35:28 PM »
Sorry but I don't understand why yo have had a problem with your DB.

Regarding the script:
1. is your class included?
2. have problemes declaring $au?
Code: [Select]
$au = new activeUsers;
3. After it try printing sometihng like
Code: [Select]
$users_online = $au->numActive(); //number of users online
echo $users_online;

If this work then go for the template parsing...
Put something like {u_online} y your template and then tell page_header.php to parse it...
Code: [Select]
$site_template->register_vars(array("media_url" => MEDIA_PATH,
"thumb_url" => THUMB_PATH,
...
"url_member" => $site_sess->url("member.php"),
"u_online" => $users_online,
"url_lost_password" => $site_sess->url("member.php?action=lostpassword")
));

You only have to add
Code: [Select]
u_online" => $users_online,
to the array.
If you don't tell me what kind of errors you have (or I have) I cannot help  you  :wink: