Page 1 of 1

PHP Chat Script - Set CHATDIR with value from variable

Posted: 08 Mar 2015, 10:48
by hups
hello,
i have a problem, i set the chatdir from database :

Code: Select all

define('CHATDIR', '../chattxt/'.$usernamerow.'/');
// the $usernamerow= 'hups';  
when i set this the chat is not showing txt / dir is wrong.

when i set the name directly all is ok:

Code: Select all

define('CHATDIR', '../chattxt/hups/');
i must set the dir from database why is this wrong ??

sorry for bad english.

PHP Chat Script - Set CHATDIR with value from variable

Posted: 08 Mar 2015, 11:17
by Admin
Hello
Your variable $usernamerow with the value added in CHATDIR must be defined before to set the CHATDIR constant.
Like in this example.

Code: Select all

$usernamerow = 'hups';  // here set its value with data from database
define('CHATDIR', '../chattxt/'. $usernamerow .'/'); 

PHP Chat Script - Set CHATDIR with value from variable

Posted: 08 Mar 2015, 12:18
by hups
Thanks for help but this is not going . the chat show nothing.
when i write this:

Code: Select all

$userrow=$row['username'];
$user = ''.$userrow.'';
define('CHATDIR','chattxt/'.$user.'/'); 
the chat is false not showing Why ??

PHP Chat Script - Set CHATDIR with value from variable

Posted: 08 Mar 2015, 12:50
by Admin
Apply this echo after CHATDIR to see what value /address contains:

Code: Select all

echo CHATDIR;
The problem is not from the chat script, but from the way you get data from database.
Check what value has the variable $userrow or $user; with:

Code: Select all

var_dump($userrow);
If it is null or false, the problem is in the code that gets data from database, or in the database table. For this, you can open a new topic (in the PHP-MySQL section) with that code and the problem you face with it.

PHP Chat Script - Set CHATDIR with value from variable

Posted: 08 Mar 2015, 13:13
by hups

Code: Select all

$userrow=$row['username'];
$user = ''.$userrow.'';
define('CHATDIR','chattxt/'.$user.'/');

echo CHATDIR;
// show: chattxt/hups/

var_dump($userrow); 
// show:  string(4) "hups"  

PHP Chat Script - Set CHATDIR with value from variable

Posted: 08 Mar 2015, 13:39
by Admin
In a previous code, the path to "chattxt" directory was: "../chattxt/", now is without "../".
1. Check to have correct path to the "chattxt" directory according to the php file location.
2. In the "chattxt/" on server you must have the "hups/" folder (or what name is set in that variable) with writable permissions for php (CHMOD 0755, or 0777).

The cause can be an incorrect path, missing folder, or without writable permissions.
- If it works when you set the name directly, then it should work if the name it is from variable.

PHP Chat Script - Set CHATDIR with value from variable

Posted: 08 Mar 2015, 15:48
by Admin
I made the Chat script to can be used with sub-folders in the "chattxt/" directory for chatrooms.
Download again the script from: https://coursesweb.net/php-mysql/script-chat-simple_s2 , and test it.

In the Read.html file there is this note about sub-folder:

The "chattxt/" is the default directory in which the txt files with chatrooms are stored, but you can also use sub-folders added in "chattxt/" to store and use txt files.
- The sub-folder can be set in the $c_subdir variable (defined in "setchat.php" line 29), default is empty. This is useful if you want to use dinamically directory with chatrooms.

- The script creates automatically the sub-folder in "chattxt/", with the name added in $c_subdir and CHMOD 0755.