How to retrieve username for use in chat system?

This forum is for general questions about extensions for Joomla! version 1.5.x.

Moderator: General Support Moderators

Forum rules
Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting, this means YOU.
Forum Post Assistant - If you are serious about wanting help, you will use this tool to help you post.
Locked
User avatar
deegiijoom
Joomla! Apprentice
Joomla! Apprentice
Posts: 26
Joined: Thu Jan 31, 2008 4:25 pm
Location: Mongolia
Contact:

How to retrieve username?

Post by deegiijoom » Fri Feb 22, 2008 1:03 pm

Hi all, how to get username?
anyone knows this help me.
I did
echo($_SESSION['username']);
but nothing output.
else I may be need to change ['username'].
do you have another way?
Last edited by pe7er on Wed Feb 27, 2008 7:38 pm, edited 1 time in total.
Reason: Title changed to normal caps. Please do not use ALLCAPS.

User avatar
tusker
Joomla! Ace
Joomla! Ace
Posts: 1075
Joined: Tue Dec 25, 2007 2:15 pm
Location: Baroda - India
Contact:

Re: HOW TO GET USER NAME?

Post by tusker » Fri Feb 22, 2008 2:06 pm

Do you want it as a frontpage out put or what? Tell exactly what you want to do so that you can get proper help. Check in your sql DB and replace it with the value there..
ONE WORLD OPEN WORLD - WAR TODAY GIVE PEACE A CHANCE
http://indiavoice.info - India News & Information Portal
http://indiadaily.indiavoice.info - India Daily Infotainment

(Powered by Joomla!)

User avatar
deegiijoom
Joomla! Apprentice
Joomla! Apprentice
Posts: 26
Joined: Thu Jan 31, 2008 4:25 pm
Location: Mongolia
Contact:

Re: HOW TO GET USER NAME?

Post by deegiijoom » Fri Feb 22, 2008 2:58 pm

I made little web chat system but I don't know how to get username.
when user logged in as a username but I don't know how to get the username.
I use joomla 1.5 .
how does the joomla register the user in session?.
e.g /session_register("username"); /
$_session['username'];
I think I need to use another word instead of username.

your any help is important me.
thank you for replying.

igrimpe
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 234
Joined: Wed Feb 20, 2008 8:59 am

Re: HOW TO GET USER NAME?

Post by igrimpe » Fri Feb 22, 2008 3:10 pm

Dig into the Joomla Framework ...
All necessary informations are accessed via Jxxxxx classes. In your case, JUser, JApplication etc would be a good starting point.

User avatar
iosoft
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 143
Joined: Sun Dec 10, 2006 3:33 pm
Location: Kolkata, INDIA
Contact:

Re: HOW TO GET USER NAME?

Post by iosoft » Fri Feb 22, 2008 3:35 pm

use this -

Code: Select all

global $my;
$my->id;
$my->name
print_r($my);
Then send this info as GET parameter to your chat software.

igrimpe
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 234
Joined: Wed Feb 20, 2008 8:59 am

Re: HOW TO GET USER NAME?

Post by igrimpe » Fri Feb 22, 2008 4:01 pm

Only works if legacy mode is enabled:

Code: Select all

// Handle legacy globals if enabled
		if ($mainframe->getCfg('legacy'))
		{
			// Include legacy globals
			global $my, $database, $acl, $mosConfig_absolute_path;
If legacy mode is not enabled you are still on:
JFactory::getUser();
;)

User avatar
deegiijoom
Joomla! Apprentice
Joomla! Apprentice
Posts: 26
Joined: Thu Jan 31, 2008 4:25 pm
Location: Mongolia
Contact:

Re: HOW TO GET USER NAME?

Post by deegiijoom » Fri Feb 22, 2008 4:21 pm

hi all,
many thanks for all replying.

I think It isn't difficult getting the username from currenty SESSION.
when user logged in my site. The Joomla starts a SESSION with username.
I will try all advices.
I'll finish it.
thanks. :)
Last edited by deegiijoom on Sat Feb 23, 2008 5:08 am, edited 1 time in total.

Aurogha
Joomla! Apprentice
Joomla! Apprentice
Posts: 12
Joined: Fri Feb 22, 2008 3:21 pm

Re: HOW TO GET USER NAME?

Post by Aurogha » Fri Feb 22, 2008 4:29 pm

<html>
<head>
<title>Documento senza titolo</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
Inserimento di una Nuova Segnalazione :
<form action="ConfermaPegasoCS.php" method="post">
<p>Data della segnalazione:
<input type="text" Name="txtdatseg">
<br>
Ragione Sociale:
<input type="text" Name="txtragsoc">
<br>
Cognome:
<input type="text" Name="txtcognome">
<br>
Nome:
<input type="text" Name="txtnome">
<br>
Indirizzo:
<input type="text" name="txtindirizzo">
<br>
C.A.P.:
<input type="text" name="txtcap">
<br>
Località:
<input type="text" name="txtlocalita">
<br>
Provincia:
<input type="text" name="txtprovincia">
<br>
Partita IVA:
<input type="text" name="txtpariva">
<br>
Telefono:
<input type="text" name="txttelefono">
<br>
Fax:
<input type="text" name="txtfax">
<br>
Email:
<input type="text" name="txtemail">
<br>
<input type="submit" Value="Aggiungi" >
</p>
<p>NomeLogIn: <input type="text" Name="IDLog">

<?php /////////////////////////////////////////////////////// ?>

</form>


</body>
</html>

how i can input on textbox IDLog the username of current session? plz i need someone help me!!!

Aurogha
Joomla! Apprentice
Joomla! Apprentice
Posts: 12
Joined: Fri Feb 22, 2008 3:21 pm

Re: HOW TO GET USER NAME?

Post by Aurogha » Fri Feb 22, 2008 4:37 pm

i use this code but i think it isn't correct

$VarUser = $my-> username
print "the username is $VarUser"

i need to insert in a variable current session username sorry if i repeat my message but i think that the people can't understand my problem..

Aurogha
Joomla! Apprentice
Joomla! Apprentice
Posts: 12
Joined: Fri Feb 22, 2008 3:21 pm

Re: HOW TO GET USER NAME?

Post by Aurogha » Fri Feb 22, 2008 4:45 pm

the code of the page after the click on the button by the user is it:

<html>
<head>
<title>Documento senza titolo</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
Inserimento di una Nuova Segnalazione :
<form action="ConfermaPegasoCS.php" method="post">
<p>
Data della segnalazione:
<input type="text" Name="txtdatseg">
<br>
Ragione Sociale:
<input type="text" Name="txtragsoc">
<br>
Cognome:
<input type="text" Name="txtcognome">
<br>
Nome:
<input type="text" Name="txtnome">
<br>
Indirizzo:
<input type="text" name="txtindirizzo">
<br>
C.A.P.:
<input type="text" name="txtcap">
<br>
Località:
<input type="text" name="txtlocalita">
<br>
Provincia:
<input type="text" name="txtprovincia">
<br>
Partita IVA:
<input type="text" name="txtpariva">
<br>
Telefono:
<input type="text" name="txttelefono">
<br>
Fax:
<input type="text" name="txtfax">
<br>
Email:
<input type="text" name="txtemail">
<br>
<input type="submit" Value="Aggiungi" ><?php print "sei connesso con l'utente $VarUtente"?>
</p>
</form>

<?php
//connessione al db
$hostname = "localhost";
$username = "root";
$password = "";
$conn = mysql_connect($hostname,$username,$password);
if (! $conn)
{
echo ("Errore durante la connessione a MySQL.");
exit();
}
else
{
echo ("Connessione a MySQL effettuata con successo.");
}
//inizio operazioni
//selezione del database
mysql_select_db("pegasocs");
//assegnazione delle variabili
$VarCodSeg = " ";
$VarDatSeg = $_POST["txtdatseg"];
$VarRagSoc = $_POST["txtragsoc"];
$VarCognome = $_POST["txtcognome"];
$VarNome = $_POST["txtnome"];
$VarIndirizzo = $_POST["txtindirizzo"];
$VarCap = $_POST["txtcap"];
$VarLocalita = $_POST["txtlocalita"];
$VarProvincia = $_POST["txtprovincia"];
$VarParIva = $_POST["txtpariva"];
$VarTelefono = $_POST["txttelefono"];
$VarFax = $_POST["txtfax"];
$VarEmail = $_POST["txtemail"];
$VarPartner = "HERE I NEED TO MEMORIZE THE USERNAME OF CURENT SESSION";
$VarStaSeg = " ";
$VarNote = "";
//Codice SQL
$strSQL = "INSERT INTO segnalazioni ( CodiceSegnalazione, DataSegnalazione, RagioneSociale, Cognome, Nome, Indirizzo, CAP, Localita, Provincia, PartitaIVA, Telefono, Fax, Email, Partner, StatoSegnalazione, Note) ";
$strSQL .= "VALUES ('$VarCodSeg', '$VarDatSeg', '$VarRagSoc', '$VarCognome', '$VarNome', '$VarIndirizzo', '$VarCap', '$VarLocalita', '$VarProvincia', '$VarParIva', '$VarTelefono', '$VarFax', '$VarEmail', '$VarPartner', '$VarStaSeg', '$VarNote')";
if (! mysql_query($strSQL))
{
echo("Errore nel comando INSERT");
exit();
}
echo("Segnalazione effettuata con successo.");
//fine codice SQL
//invio di una mail
mail("dago_goda@yahoo.it","Nuova Segnalazione effettuata in data $VarDatSeg", "nuova segnalazione inviata, vedere segnalazione del sig. $VarCognome $VarNome o eventualmente contattare tramite l'indirizzo email $VarEmail ");
//chiusura della connessione al db
mysql_close($conn);

?>
</body>
</html>

User avatar
deegiijoom
Joomla! Apprentice
Joomla! Apprentice
Posts: 26
Joined: Thu Jan 31, 2008 4:25 pm
Location: Mongolia
Contact:

How to retrieve username for use in chat system?

Post by deegiijoom » Wed Feb 27, 2008 5:47 pm

Hi all,
I use joomla 1.5
how to get currenty logged username?.
my usage is putting the username in chat system.
Last edited by pe7er on Wed Feb 27, 2008 7:35 pm, edited 1 time in total.
Reason: Title changed to normal caps. Please do not use ALLCAPS.

User avatar
pe7er
Joomla! Master
Joomla! Master
Posts: 22233
Joined: Thu Aug 18, 2005 8:55 pm
Location: Nijmegen, The Netherlands
Contact:

Re: How to retrieve username for use in chat system?

Post by pe7er » Wed Feb 27, 2008 7:37 pm

You can use something like:

Code: Select all

global $my;
$username = $my->username;
to retrieve the username.
Kind Regards,
Peter Martin, Global Moderator
https://db8.nl - Joomla specialist, Nijmegen, Nederland
Co-developer of d2 Content https://data2site.com/joomla-extensions/d2-content

Aurogha
Joomla! Apprentice
Joomla! Apprentice
Posts: 12
Joined: Fri Feb 22, 2008 3:21 pm

Re: How to retrieve username for use in chat system?

Post by Aurogha » Thu Feb 28, 2008 8:26 am

Peter, i use this code for do an example and verify the effective code working:

Code: Select all

<?php 
  global $my;
  $username = $my->username;
  print "your username is $username " 
  ?>
the output is this:

Code: Select all

your username is
what's i wrong?

igrimpe
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 234
Joined: Wed Feb 20, 2008 8:59 am

Re: How to retrieve username for use in chat system?

Post by igrimpe » Thu Feb 28, 2008 9:22 am

hmmm. let's think ...
you create a php file. upload it. run it and you get this result?
I wonder: What makes you think, that if you run any php script OUPTSIDE THE SCOPE OF JOOMLA, you have access to any variable, object, etc that is part of the Joomla framework?
You could change the code to:

Code: Select all

global $world;
  $diameter= $world->diameter;
  print "the diameter of the world is $diameter" 
[/quote]
The result is the same as with "$my" ...

I'd suggest to download a simple Joomla module and to is it as starting point for own experiments.

EDIT:
Or check this: http://forum.joomla.org/viewtopic.php?f=483&t=63383

Aurogha
Joomla! Apprentice
Joomla! Apprentice
Posts: 12
Joined: Fri Feb 22, 2008 3:21 pm

Re: How to retrieve username for use in chat system?

Post by Aurogha » Thu Feb 28, 2008 10:36 am

i forget to tell you that my joomla version is the version 1.0.13 ..... it is a problem?

igrimpe
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 234
Joined: Wed Feb 20, 2008 8:59 am

Re: How to retrieve username for use in chat system?

Post by igrimpe » Thu Feb 28, 2008 10:39 am

it is a problem?
Not for me. After being in the wrong category "security" it's now in the wrong category "1.5 - General questions"

Maybe you start with one of the HelloWorld tutorials that I mentioned?
Maybe you ask any further question about writing code for Joomla in one of the developer categories?

oc666
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 215
Joined: Wed Oct 10, 2007 9:46 am
Location: Israel, TA
Contact:

Re: How to retrieve username for use in chat system?

Post by oc666 » Thu Feb 28, 2008 11:01 pm

Try this two functions(J!1.5):

Code: Select all

function _getUser()
	{
		$session =& JFactory::getSession();
		$user = $session->get("user");
		return $user->username;
	}

	function _getUserId()
	{
		$session =& JFactory::getSession();
		$user = $session->get("user");
		return $user->id;
	}
http://www.embad.com - new way to insert ads to your website

Alex53
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 236
Joined: Mon Aug 22, 2005 11:25 am

Re: How to retrieve username for use in chat system?

Post by Alex53 » Tue Apr 15, 2008 8:21 am

Thanks oc666 that worked perfectly!

I have a little question. What other session variables are available? I cant seem to find documentation on this!

oc666
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 215
Joined: Wed Oct 10, 2007 9:46 am
Location: Israel, TA
Contact:

Re: How to retrieve username for use in chat system?

Post by oc666 » Tue Apr 15, 2008 11:42 am

Alex53 wrote: I have a little question. What other session variables are available? I cant seem to find documentation on this!
Check the JSession:
http://smink.student.utwente.nl/joomla1 ... ssion.html
JFactory:
http://smink.student.utwente.nl/joomla1 ... ctory.html

And google sometimes ;)
http://www.embad.com - new way to insert ads to your website

SpArKy87
Joomla! Apprentice
Joomla! Apprentice
Posts: 11
Joined: Sat Nov 04, 2006 11:27 am

Re: How to retrieve username for use in chat system?

Post by SpArKy87 » Mon Jun 23, 2008 7:59 am

Can I somehow forward the JUser Object to a subfolder index.php?

oc666
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 215
Joined: Wed Oct 10, 2007 9:46 am
Location: Israel, TA
Contact:

Re: How to retrieve username for use in chat system?

Post by oc666 » Mon Jun 23, 2008 3:08 pm

SpArKy87 wrote:Can I somehow forward the JUser Object to a subfolder index.php?
What do you mean forward the JUser?
http://www.embad.com - new way to insert ads to your website

User avatar
zrnchikw
Joomla! Fledgling
Joomla! Fledgling
Posts: 4
Joined: Thu Dec 20, 2007 6:05 pm

Re: How to retrieve username for use in chat system?

Post by zrnchikw » Sun Jul 20, 2008 4:51 am

Okay... I'm trying to follow along and it isn't working. I've got a 1.5 install and phpFreeChat in a sub directory. I am trying to pass the Joomla username to phpFreeChat's $nick variable.

Joomla 1.5 is here => http://community.mysite.com
phpFreeChat is here => http://community.mysite.com/chat

I have tried modifying PFC's index.php from:

Code: Select all

function _getUser()
require_once dirname(__FILE__)."/src/phpfreechat.class.php";
$params = array();
$params["title"] = "Chat Name";
$params["nick"] = "Guest".rand(1,1000);  // setup the intitial nickname 
$params["isadmin"] = true; // do not use it on production servers ;)
to the following:

Code: Select all

function _getUser()
   {
      $session =& JFactory::getSession();
      $user = $session->get("user");
      return $user->username;
   }

   function _getUserId()
   {
      $session =& JFactory::getSession();
      $user = $session->get("user");
      return $user->id;
   }

require_once dirname(__FILE__)."/src/phpfreechat.class.php";
$params = array();
$params["title"] = "Chat Name";
$params["nick"] = & JFactory::getUser();  //"Guest".rand(1,1000);  // setup the intitial nickname 
$params["isadmin"] = true; // do not use it on production servers ;)
I get the infamous error:
Fatal error: Class 'JFactory' not found in /home/mydomain/public_html/community/chat/index.php on line 20
with $params["nick"] = & JFactory::getUser(); //"Guest".rand(1,1000); // setup the intitial nickname on line 20. I'm guessing it is because I have not declared JFactory anywhere in PFC... but where do I do that?

I'm quite sure I'm missing more than I imagine, but can someone point me in the right direction?

Thanks
Will

User avatar
dizzi
Joomla! Virtuoso
Joomla! Virtuoso
Posts: 3136
Joined: Fri Dec 21, 2007 9:36 pm
Location: Yorkshire, UK

Re: How to retrieve username for use in chat system?

Post by dizzi » Mon Aug 25, 2008 6:05 pm

Hi

You are doing a few thing wrongly here.

Firstly you are using a "=&" assignment operator for the "nick" parameter which most likey will not be recognised.
Secondly the function:

Code: Select all

function _getUser()
   {
      $session =& JFactory::getSession();
      $user = $session->get("user");
      return $user->username;
   }
returns the session's logged in username, which is the value you are after. So instead of what you currently have:

Code: Select all

$params["nick"] = & JFactory::getUser();
you need,

Code: Select all

$params["nick"] = _getUser();
Regards
Freedom of expression ... some may try to suppress it but they can never take it away ...
There is no problem a good miracle can't fix.


Locked

Return to “Extensions for Joomla! 1.5”