Simple Machines Community Forum

General Community => Scripting Help => Aiheen aloitti: vandeperre - maaliskuu 14, 2007, 04:58:40 IP

Otsikko: get username
Kirjoitti: vandeperre - maaliskuu 14, 2007, 04:58:40 IP
hi, i'm setting up an irc-chatroom for my website and i wanted to know how i can 'get' the username from the forum

example:
i'm logged in and i click on the chat button
the chat window opens and i get a chat with the username from the forum (automatically)

the code to put automatically a nickname in the chatwindow is
<param name="nick" value="yournickname">
(where "yournickname" stands, there needs to come a code for the forumusername...
Otsikko: Re: get username
Kirjoitti: Aquilo - maaliskuu 14, 2007, 10:51:33 IP
if this is in any way part of the forum, then it's simple as $user_info['username'] or $user_info['name']

otherwise you'll need SSI.php or the api script!
Otsikko: Re: get username
Kirjoitti: vandeperre - maaliskuu 15, 2007, 05:04:52 AP
Lainaus käyttäjältä: Aquilo - maaliskuu 14, 2007, 10:51:33 IP
if this is in any way part of the forum, then it's simple as $user_info['username'] or $user_info['name']

otherwise you'll need SSI.php or the api script!
no, it is an external page outside the forum, but maybe i can include ssi.php and take a bit of source and put it in ssi.php??

do you know how??
Otsikko: Re: get username
Kirjoitti: KGIII - maaliskuu 15, 2007, 05:08:19 AP
I don't know how but have you taken a look at the intergrated chat mod to see how they did it?
Otsikko: Re: get username
Kirjoitti: vandeperre - maaliskuu 15, 2007, 05:30:22 AP
i'm trying to do it ... and i've tried this:
<?php 
function username()
{
global $user_info;

if ($user_info['is_guest'])
echo 'gast';
else
echo '($user_info['name'])';  //   <=here is the error!
}
?>


but i get the error 'parse error, unexpected T_STRING, expecting ',' or ';' in /home/www/the-elite.freehostia.com/forum2/SSI.php on line 1662', line 1662 is the line under 'else' ...
Otsikko: Re: get username
Kirjoitti: vandeperre - maaliskuu 15, 2007, 05:52:45 AP
and, now i've took a look to the integrated chat mod but they did it totally different than i did..

sorry for my bad english, but it is better than YOUR dutch, i think...
Otsikko: Re: get username
Kirjoitti: KGIII - maaliskuu 15, 2007, 06:18:41 AP
If you have ever seen me speak Dutch you would be certain that I should only speak English. Anyhow - their method works and all I can say is that I would try to go with that as your example if possible. If not then there maybe more in the API for either SMF or for your IRC server that you can look into but the user_info['name'] variable should be what you are looking for. Remember you will need user_info registered as a global to do so effeciently like you have already.
Otsikko: Re: get username
Kirjoitti: vandeperre - maaliskuu 15, 2007, 10:55:55 AP
but it doesn't work, i have a 'backup plan' but it doesn't work neither, and, i'm right: my english is better than your dutch!

heb ik geen gelijk?? :p
Otsikko: Re: get username
Kirjoitti: KGIII - maaliskuu 16, 2007, 09:44:25 AP
ja bent u juist. ;)
Otsikko: Re: get username
Kirjoitti: vandeperre - maaliskuu 18, 2007, 07:05:17 AP
you are wrong
this is correct: ja, u bent juist (very polite)
or: ja, je hebt gelijk (between 2 friends)
or in dialect: ge hed het just
Otsikko: Re: get username
Kirjoitti: Daniel15 - maaliskuu 18, 2007, 07:11:41 AP
Change your code above to:

<?php 
function username()
{
global $user_info;
echo ($user_info['is_logged']) ? $user_info['name'] : 'gast';
}
?>



This should work :)
Otsikko: Re: get username
Kirjoitti: vandeperre - maaliskuu 18, 2007, 11:44:24 AP
edit: the error was caused by a mod, but now it always says 'gast' (guest in english) even when i'm logged in in smf, you can see the forum here (http://the-elite.freehostia.com/forum2) and the chat here (http://the-elite.freehostia.com/chat/test.php)
Otsikko: Re: get username
Kirjoitti: codenaught - maaliskuu 18, 2007, 12:36:09 IP
There is no $user_info['is_logged']. Try using this instead:

function username()
{
global $context;
echo ($context['user']['is_logged']) ? $context['user']['name'] : 'gast';
}
Otsikko: Re: get username
Kirjoitti: vandeperre - maaliskuu 18, 2007, 03:21:56 IP
1 more question: is it possible to let the script determine that the username is 1 or more words? because my login is ome joop and when i login to the chat only ome is visible... so when it are 2 words it wil give the name of the user and not the username..
Otsikko: Re: get username
Kirjoitti: Aquilo - maaliskuu 22, 2007, 07:03:20 IP
function username()
{
global $context;
echo str_replace(' ', '_', ($context['user']['is_logged']) ? $context['user']['name'] : 'gast');
}
Otsikko: Re: get username
Kirjoitti: vandeperre - maaliskuu 23, 2007, 12:30:36 IP
thanx, this helps.