Problem understanding path variables

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
MarkHoward
Forum Newbie
Posts: 21
Joined: Sun Nov 22, 2009 7:15 pm

Problem understanding path variables

Post by MarkHoward »

I am trying to display the number of people in the (phpfreechat) chat room on another webpage.
Chat page: http://www.nzmotorhome.co.nz/NZMotorhomeChat/chat.php.
Other page: http://www.nzmotorhome.co.nz/directory/directory.php.
In chat.php I have

Code: Select all

//next 7 lines of code from phpBB "Sessions Integration"
    define('IN_PHPBB', true);
    $phpbb_root_path = '../NZMotorhomeForum/';
//    $phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
    $phpEx = substr(strrchr(__FILE__, '.'), 1);
    include($phpbb_root_path . 'common.' . $phpEx);
 
    // Start session management
    $user->session_begin();
    $auth->acl($user->data);
    $user->setup();
.
.
.
.
$params["serverid"] = md5("ForumChat"); // calculate a unique id for this chat
 
In directory.php I have

Code: Select all

       <?php
            require_once dirname(__FILE__)."/chat/src/pfcinfo.class.php";
            $info  = new pfcInfo( md5("ForumChat") );
            // NULL is used to get all the connected users, but you can specify
            // a channel name to get only the connected user on a specific channel
            $users = $info->getOnlineNick(NULL);
            echo '<div align="center">';
            $info = "";
            $nb_users = count($users);
            if ($nb_users <= 0)
              $info = "<center>%d users in the Chat Room</center>";
            echo "</div>";
            echo "<div>";
            echo "<p>".sprintf($info, $nb_users)."</p>";
            echo "<ol>";
            foreach($users as $u)
            {
              echo "<li>".$u."</li>";
            }
            echo "</ol>";
            echo "</div>";
           ?>
 
When I log in on chat.php and then open directory.php (note: the directory link on the chat page opens directory.html, not directroy.php), I get the following error

Code: Select all

Warning: require_once(/home/nzmotorh/public_html/directory/chat/src/pfcinfo.class.php) 
[function.require-once]: failed to open stream: No such file or directory in /home/nzmotorh/public_html/directory/directory.php on line 76
 
Fatal error: require_once() [function.require]: Failed opening required '/home/nzmotorh/public_html/directory/chat/src/pfcinfo.class.php' 
(include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/nzmotorh/public_html/directory/directory.php on line 76
I've been trying to get this sorted. on and off, for weeks now. I feel it must be something really simple about defining paths that I don't understand.

Please can someone help me, or tell me what other information I need to provide.
This is just a test and eventually, when I get it going, I want to implement it in a phpBB3 overall-footer.php file.
cpetercarter
Forum Contributor
Posts: 474
Joined: Sat Jul 25, 2009 2:00 am

Re: Problem understanding path variables

Post by cpetercarter »

I assume that you have checked (probably a hundred times!) that there is in fact a file pfcinfo.class.php at the location mentioned in the error message.

Two possible reasons why the script cannot find it are permissions, and an open_basedir() restriction in php.ini. Who "owns" pfcinfo.class.php and what permissions are set for it?
MarkHoward
Forum Newbie
Posts: 21
Joined: Sun Nov 22, 2009 7:15 pm

Re: Problem understanding path variables

Post by MarkHoward »

Thank you for your reply. You may have guessed, I'm an absolute newbie.
I had copied the code from an example of how to do this (display # people in Chatroom) without understanding PHP.
the __FILE__ variable was used in the example but did not match my folder structure.

I have now replaced

Code: Select all

#             require_once dirname(__FILE__)."/chat/src/pfcinfo.class.php";
 
with

Code: Select all

           require_once "/home/nzmotorh/public_html/NZMotorhomeChat/chat/src/pfcinfo.class.php";
 
and got
Warning: require_once(/home/nzmotorh/public_html/NZMotorhomeChat/chat/src/pfcinfo.class.php) [function.require-once]: failed to open stream: No such file or directory in /home/nzmotorh/public_html/directory/directory.php on line 76

Fatal error: require_once() [function.require]: Failed opening required '/home/nzmotorh/public_html/NZMotorhomeChat/chat/src/pfcinfo.class.php' (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/nzmotorh/public_html/directory/directory.php on line 76
Then I looked closer (since your post gave me confidence that this, indeed was where the problem lay) and saw that the /chat was not needed.

It is now resolved - yet I'm sure I had been there several times before.

Thank you very much for helping me with that.
MarkHoward
Forum Newbie
Posts: 21
Joined: Sun Nov 22, 2009 7:15 pm

Re: Problem understanding path variables

Post by MarkHoward »

Problem #2.
Trying, now, to get it going on localhost. I have changed the path to relative in directory.php: ie from this

Code: Select all

require_once "/home/nzmotorh/public_html/NZMotorhomeChat/src/pfcinfo.class.php";
to this

Code: Select all

           require_once "../NZMotorhomeChat/src/pfcinfo.class.php";
 
and it is working OK on webhost.
BUT now, if I try to open chat.php on localhost I get the following error messages
Deprecated: Assigning the return value of new by reference is deprecated in C:\Data\xampp\htdocs\NZMotorhomeChat\src\phpfreechat.class.php on line 225

Deprecated: Assigning the return value of new by reference is deprecated in C:\Data\xampp\htdocs\NZMotorhomeChat\src\phpfreechat.class.php on line 354

Deprecated: Assigning the return value of new by reference is deprecated in C:\Data\xampp\htdocs\NZMotorhomeChat\src\phpfreechat.class.php on line 404

Deprecated: Assigning the return value of new by reference is deprecated in C:\Data\xampp\htdocs\NZMotorhomeChat\src\phpfreechat.class.php on line 535

Deprecated: Assigning the return value of new by reference is deprecated in C:\Data\xampp\htdocs\NZMotorhomeChat\src\phpfreechat.class.php on line 565

Deprecated: Assigning the return value of new by reference is deprecated in C:\Data\xampp\htdocs\NZMotorhomeChat\src\pfccommand.class.php on line 70

Deprecated: Assigning the return value of new by reference is deprecated in C:\Data\xampp\htdocs\NZMotorhomeChat\src\pfccommand.class.php on line 90

Deprecated: Assigning the return value of new by reference is deprecated in C:\Data\xampp\htdocs\NZMotorhomeChat\src\pfccontainer.class.php on line 57
[phpBB Debug] PHP Notice: in file C:/Data/xampp/htdocs/NZMotorhomeChat/src/pfcuserconfig.class.php on line 25: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at C:/Data/xampp/htdocs/NZMotorhomeChat/src/phpfreechat.class.php:225)
[phpBB Debug] PHP Notice: in file C:/Data/xampp/htdocs/NZMotorhomeChat/src/pfcuserconfig.class.php on line 25: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:/Data/xampp/htdocs/NZMotorhomeChat/src/phpfreechat.class.php:225)
As I said, this is working fine on a webhost but not on localhost.
I'd be very grateful for some pointers as to what these messages (particularly the last two) might indicate.
cpetercarter
Forum Contributor
Posts: 474
Joined: Sat Jul 25, 2009 2:00 am

Re: Problem understanding path variables

Post by cpetercarter »

I guess that you have a more recent version of php on your localhost computer than on the server. Recent versions of php "deprecate" the passing of certain values by reference rather than by value, and the warning messages are simply telling you this.

What to do? As a temporary measure, you could suppress the error messages - put the following at the beginning of your script:

Code: Select all

error_reporting(^E_DEPRECATED);
Have a look at http://www.php.net/manual/en/function.e ... orting.php for more information.

In the longer term, someone (?you. ?the original author) needs to rewrite phpfreechat.class.php so that it conforms to modern php standards.

You can ignore the final error messages about "headers already sent" - they will disappear if you get rid of the other messages.
MarkHoward
Forum Newbie
Posts: 21
Joined: Sun Nov 22, 2009 7:15 pm

Re: Problem understanding path variables

Post by MarkHoward »

Thanks very much for that advice, Peter.
I'll try that tomorrow (the temp fix - not the re-write!)
This is a very useful forum :)
Post Reply