How to get user id
-
- Joomla! Fledgling
- Posts: 1
- Joined: Mon Apr 07, 2008 9:39 am
How to get user id
Hi,
Anyone can help me with de complet code for extract the user id or user name in the joomla 1.5 with the external scripts.
Thanks,
LF
Anyone can help me with de complet code for extract the user id or user name in the joomla 1.5 with the external scripts.
Thanks,
LF
- wojtekkk87
- Joomla! Apprentice
- Posts: 34
- Joined: Thu Mar 29, 2007 6:25 pm
- Location: Poland
- Contact:
Re: How to get user id
What kind of external script?\I think it should be helpful:
http://dev.joomla.org/component/option, ... tableuser/
or
it should works ok;)
http://dev.joomla.org/component/option, ... tableuser/
or
Code: Select all
$user =& JFactory::getUser();
$user->get('id');
-
- Joomla! Enthusiast
- Posts: 236
- Joined: Mon Aug 22, 2005 11:25 am
Re: How to get user id
Hi, I am trying this code ;
But all I get is 'Object' whoever is logged in. any ideas?
Code: Select all
<?php
defined('_JEXEC') OR defined('_VALID_MOS') OR die( "Direct Access Is Not Allowed" );
echo "Hello";
echo "<br><br>User: ";
$jAp= & JFactory::getApplication();
$user =& JFactory::getUser();
$user->get('id');
echo $user;
?>
-
- Joomla! Fledgling
- Posts: 1
- Joined: Tue Apr 15, 2008 9:43 pm
Re: How to get user id
Hi,
try this:
Bye,
moggway
try this:
Code: Select all
$user =& JFactory::getUser();
$usr_id = $user->get('id');
echo $usr_id;
moggway
-
- Joomla! Enthusiast
- Posts: 236
- Joined: Mon Aug 22, 2005 11:25 am
Re: How to get user id
thanks, it works. I am also using a couple of functions member oc66 posted in another thread.
So now I have Joomla's ldap authentication working, I can get the php scripts included by the Jumi plugin to get the currently logged in user, but I cant get php to bind to the AD to check that this user belongs to a group. I am using a class called adldap, but its never worked for me since we upgraded to Windows Server 2003 from 2000.
So now I have Joomla's ldap authentication working, I can get the php scripts included by the Jumi plugin to get the currently logged in user, but I cant get php to bind to the AD to check that this user belongs to a group. I am using a class called adldap, but its never worked for me since we upgraded to Windows Server 2003 from 2000.
-
- Joomla! Apprentice
- Posts: 6
- Joined: Mon Mar 05, 2007 9:06 am
Re: How to get user id
Hello, I'm trying to implement this in a php script but it doesn;t seem to get any values. The whole user array values are 0 and nullmoggway wrote:Hi,
try this:
Bye,Code: Select all
$user =& JFactory::getUser(); $usr_id = $user->get('id'); echo $usr_id;
moggway
Do i have to include any more classes ?
I have a testauth.php script which i call from a joomla article with a link.
Thanks in advance.
John
-
- Joomla! Apprentice
- Posts: 6
- Joined: Mon Mar 05, 2007 9:06 am
Re: How to get user id
It seems one way to do it is to load the framework with
But isn't that an overkill ? Can it be done without reloading the whole framework in every php script i'm using ?
Code: Select all
require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' );
require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' );
$mainframe =& JFactory::getApplication('site');
$mainframe->initialise();
- dam-man
- Joomla! Exemplar
- Posts: 7961
- Joined: Fri Sep 09, 2005 2:13 pm
- Location: The Netherlands
- Contact:
Re: How to get user id
sorry ilektrojohn, what you're telling here is not the way to do this..
Take a look at for example to the login module, if you're lofgged in it will show your name.
This is the method, this session is started, and allmost all data is from jos_user with the specific id thats logged in. Is availeble through the session
Take a look at for example to the login module, if you're lofgged in it will show your name.
This is the method, this session is started, and allmost all data is from jos_user with the specific id thats logged in. Is availeble through the session
Robert Dam - Joomla Forum Moderator
Dutch Boards | Joomla Coding Boards | English Support Boards
Dutch Boards | Joomla Coding Boards | English Support Boards
-
- Joomla! Apprentice
- Posts: 6
- Joined: Mon Mar 05, 2007 9:06 am
Re: How to get user id
I was pretty sure that way was not the way to go, so there's no need to be sorry
Still I cannot see how the information about the user is taken from session in mod login. I can't see no call to JSession class in mod_login.php or helper.php .
JFactory::getuser is used there also
All I'm trying to do is implement a way for a non joomla application running in the same server to get user credentials (only their username) from joomla , so I can use it to authenticate the user.
I think I know how to get the information from the session, but every time i try it i get null values whether the user is logged in in joomla or not.
Could you or somebody else provide me with a minimal working example?
Meaning something like
Still I cannot see how the information about the user is taken from session in mod login. I can't see no call to JSession class in mod_login.php or helper.php .
JFactory::getuser is used there also
All I'm trying to do is implement a way for a non joomla application running in the same server to get user credentials (only their username) from joomla , so I can use it to authenticate the user.
I think I know how to get the information from the session, but every time i try it i get null values whether the user is logged in in joomla or not.
Could you or somebody else provide me with a minimal working example?
Meaning something like
Code: Select all
require someclass;
require someotherclass;
//ok now you got the session values available do as you please with them
- dam-man
- Joomla! Exemplar
- Posts: 7961
- Joined: Fri Sep 09, 2005 2:13 pm
- Location: The Netherlands
- Contact:
Re: How to get user id
I've tested this:
And this is working properly in Joomla! 1.5.2
Check in for example ../modules/mod_login/mod_login.php
Here you will find:
And in the template they're using this:
This will show you your name. If you change this into "id" it will work
Code: Select all
<?php
$user =& JFactory::getUser();
echo $user->get('id') ;
?>
Check in for example ../modules/mod_login/mod_login.php
Here you will find:
Code: Select all
$user =& JFactory::getUser();
And in the template they're using this:
Code: Select all
<?php echo JText::sprintf( 'HINAME', $user->get('name') ); ?>
Robert Dam - Joomla Forum Moderator
Dutch Boards | Joomla Coding Boards | English Support Boards
Dutch Boards | Joomla Coding Boards | English Support Boards
-
- Joomla! Apprentice
- Posts: 6
- Joined: Mon Mar 05, 2007 9:06 am
Re: How to get user id
Yes i understand what you re saying but i think you dont understand what I'm trying to do.
If I use the getUser function in module or component it works, but what i'm trying to do is access the method from a php script that is in the same server , but not part of joomla .
Lets say i have a simple php script that says
It;s obvious that it doesn't work.
If I add
in the begining of the script i dont;get any warnings, as it knows where to find the specific classes and functions,
but getUser always returns null.
Now, if i also add
What I'm asking is what are the minimal classes i will have to load in order for getUSer to work .
Thanks in advance.
If I use the getUser function in module or component it works, but what i'm trying to do is access the method from a php script that is in the same server , but not part of joomla .
Lets say i have a simple php script that says
Code: Select all
<?php
echo 'hello';
$user =& JFactory::getUser();
echo 'You ar user' .$user.'! Welcome!';
?>
If I add
Code: Select all
require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' );
require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' );
but getUser always returns null.
Now, if i also add
I get the user name.$mainframe =& JFactory::getApplication('site');
$mainframe->initialise();
What I'm asking is what are the minimal classes i will have to load in order for getUSer to work .
Thanks in advance.
- jaguas
- Joomla! Apprentice
- Posts: 13
- Joined: Thu Sep 06, 2007 10:33 am
Re: How to get user id
Hello.
I have a form in a .php file in the same server of joomla but in another database.
I need to insert the username in the table.
With this code:
$user_joomla =& JFactory::getUser();
$usr_username = $user_joomla->get('username');
I get this error:
Class 'JFactory' not found
How can I solve this?
I have a form in a .php file in the same server of joomla but in another database.
I need to insert the username in the table.
With this code:
$user_joomla =& JFactory::getUser();
$usr_username = $user_joomla->get('username');
I get this error:
Class 'JFactory' not found
How can I solve this?
- dam-man
- Joomla! Exemplar
- Posts: 7961
- Joined: Fri Sep 09, 2005 2:13 pm
- Location: The Netherlands
- Contact:
Re: How to get user id
did you connected the database by this script?
Robert Dam - Joomla Forum Moderator
Dutch Boards | Joomla Coding Boards | English Support Boards
Dutch Boards | Joomla Coding Boards | English Support Boards
- jaguas
- Joomla! Apprentice
- Posts: 13
- Joined: Thu Sep 06, 2007 10:33 am
Re: How to get user id
Yes.
In this script i connect to the other database (not the joomla database) to read the content and to insert new content using the form.
In this script i connect to the other database (not the joomla database) to read the content and to insert new content using the form.
-
- Joomla! Fledgling
- Posts: 4
- Joined: Sun Jun 08, 2008 3:42 pm
Re: How to get user id
I had the same problem as others. I'm using an external PHP file to attempt to access information about the currently logged on Joomla user (while not under the Joomla path).
This is the PHP code I had to add to get access to the user array.
This is the PHP code I had to add to get access to the user array.
Code: Select all
define( '_JEXEC', 1 );
define('JPATH_BASE', dirname(__FILE__) );
define( 'DS', DIRECTORY_SEPARATOR );
require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' );
require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' );
$mainframe =& JFactory::getApplication('site');
$mainframe->initialise();
$mainframe->route();
$user =& JFactory::getUser();
print_r($user);
- jaguas
- Joomla! Apprentice
- Posts: 13
- Joined: Thu Sep 06, 2007 10:33 am
Re: How to get user id
Hi.
I've been in holidays.
I tried the code but now i get this error message:
Warning: require_once(C:\Apache\htdocs\joomla\test\includes\defines.php) [function.require-once]: failed to open stream: No such file or directory in C:\Apache\htdocs\joomla\test\problems.php on line 24
Fatal error: require_once() [function.require]: Failed opening required 'C:\Apache\htdocs\joomla\test\includes\defines.php' (include_path='.;C:\php5\pear') in C:\Apache\htdocs\joomla\test\problems.php on line 24
In fact, the directory "includes" does not exist in that path.
What am i doing wrong?
I've been in holidays.
I tried the code but now i get this error message:
Warning: require_once(C:\Apache\htdocs\joomla\test\includes\defines.php) [function.require-once]: failed to open stream: No such file or directory in C:\Apache\htdocs\joomla\test\problems.php on line 24
Fatal error: require_once() [function.require]: Failed opening required 'C:\Apache\htdocs\joomla\test\includes\defines.php' (include_path='.;C:\php5\pear') in C:\Apache\htdocs\joomla\test\problems.php on line 24
In fact, the directory "includes" does not exist in that path.
What am i doing wrong?
-
- Joomla! Fledgling
- Posts: 4
- Joined: Sun Jun 08, 2008 3:42 pm
Re: How to get user id
FYI - that code is for Joomla 1.5.
I recommend you perform a search in the Joomla install directory for your "defines.php" and adjust the path accordingly.
Instead of this:
require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' );
You may just neeed to hardcode the path as follows:
require_once ( 'C:\Apache\htdocs\joomla\includes\defines.php' );
Is Joomla installed in the "test" directory ?
I recommend you perform a search in the Joomla install directory for your "defines.php" and adjust the path accordingly.
Instead of this:
require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' );
You may just neeed to hardcode the path as follows:
require_once ( 'C:\Apache\htdocs\joomla\includes\defines.php' );
Is Joomla installed in the "test" directory ?
- jaguas
- Joomla! Apprentice
- Posts: 13
- Joined: Thu Sep 06, 2007 10:33 am
Re: How to get user id
I changed the two lines like this:
Now i have this message:
No configuration file found and no installation code available. Exiting...
The Joomla 1.5 is installed here: 'C:\Apache\htdocs\joomla\'
If i change my 'problem.php' file to 'C:\Apache\htdocs\joomla\' it works fine with the first code you gave me:
and i can see the content of the array.
But i would like to organise my php files in other directorys...
Code: Select all
require_once ('C:\Apache\htdocs\joomla\includes\defines.php');
require_once ('C:\Apache\htdocs\joomla\includes\framework.php');
No configuration file found and no installation code available. Exiting...
The Joomla 1.5 is installed here: 'C:\Apache\htdocs\joomla\'
If i change my 'problem.php' file to 'C:\Apache\htdocs\joomla\' it works fine with the first code you gave me:
Code: Select all
require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' );
require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' );
But i would like to organise my php files in other directorys...
-
- Joomla! Fledgling
- Posts: 3
- Joined: Wed Jun 28, 2006 10:43 pm
Re: How to get user id
I had this same problem and ended up having to put the files in the root directory and call the mainframe getapplication. It's not pretty but it works.
-
- Joomla! Fledgling
- Posts: 1
- Joined: Tue Aug 26, 2008 10:00 am
Re: How to get user id
Hi, I've a question.
I'm using the Joomla version 1.8 .
I want to get the user ID of logged on members into an input like this:
On the place of userID should just come your ID number.
Could anyone help plz?
Thx
I'm using the Joomla version 1.8 .
I want to get the user ID of logged on members into an input like this:
Code: Select all
<input type="text" readonly="yes" value="userID">
Could anyone help plz?
Thx
-
- Joomla! Apprentice
- Posts: 30
- Joined: Sun Aug 03, 2008 5:09 pm
Re: How to get user id
ilektrojohn wrote:Yes i understand what you re saying but i think you dont understand what I'm trying to do.
If I use the getUser function in module or component it works, but what i'm trying to do is access the method from a php script that is in the same server , but not part of joomla .
Lets say i have a simple php script that saysIt;s obvious that it doesn't work.Code: Select all
<?php echo 'hello'; $user =& JFactory::getUser(); echo 'You ar user' .$user.'! Welcome!'; ?>
If I addin the begining of the script i dont;get any warnings, as it knows where to find the specific classes and functions,Code: Select all
require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' ); require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' );
but getUser always returns null.
Now, if i also addI get the user name.$mainframe =& JFactory::getApplication('site');
$mainframe->initialise();
What I'm asking is what are the minimal classes i will have to load in order for getUSer to work .
Thanks in advance.
Hi!
Im having the same problem?
Did you find a workaround ?
I have the additional problem of wanting to redirect to another directory in the same server, but after doing
i can't send no headers.... (in particular header("Location: http://sameserver/otherdirectory")$mainframe =& JFactory::getApplication('site');
$mainframe->initialise();
desperate here !
thanks in advance,
siran
- b.sanjay
- Joomla! Enthusiast
- Posts: 235
- Joined: Wed May 09, 2007 7:53 am
- Location: Bangalore, Karnataka, India
- Contact:
Re: How to get user id
Hi there ,
've u ppl tryed
As you ppl are trying to access the database outsite the Joomla..... all the things you 've to do is manually....
've u ppl tryed
Code: Select all
include_once/include "The_File_Containing_the_Class_and_Function.php";
As you ppl are trying to access the database outsite the Joomla..... all the things you 've to do is manually....
Thank you.
Regards,
Sanjay Beedi
Senior Software Engineer,
Construe Solutions, Hyderabad, AP, India
http://www.construesol.com/
Regards,
Sanjay Beedi
Senior Software Engineer,
Construe Solutions, Hyderabad, AP, India
http://www.construesol.com/
-
- Joomla! Fledgling
- Posts: 2
- Joined: Fri Oct 10, 2008 7:40 am
Re: How to get user id
So close...
It works perfectly when added onto the index page, but when I try it on my own page...
http://mysite.com/test.php
Although if I go to the page, i just get a:
"Restricted access"
Where do I define that it should be unrestricted access, but only to this page, or add this page to the unrestricted list, or something... ?
It works perfectly when added onto the index page, but when I try it on my own page...
http://mysite.com/test.php
Code: Select all
<?php
require_once ('C:\Inetpub\Domains\mySite\includes\defines.php');
require_once ('C:\Inetpub\Domains\mySite\includes\framework.php');
$mainframe =& JFactory::getApplication('site');
$mainframe->initialise();
echo 'hello';
$user =& JFactory::getUser();
echo 'You are user' .$user.'! Welcome!';
?>
Although if I go to the page, i just get a:
"Restricted access"
Where do I define that it should be unrestricted access, but only to this page, or add this page to the unrestricted list, or something... ?
-
- Joomla! Apprentice
- Posts: 38
- Joined: Sun Aug 03, 2008 6:05 am
Re: How to get user id
It's not going to work outside of Joomla! the way you're trying cause when the user goes to your non-Joomla page, he is no longer a logged-in member of the site and there's no session variables etc.
If you're really determined your script can't run inside of Joomla, you have to "get" that Joomla variables are not going to be accessible unless you specifically hand them over. So you need to write a URL for the user on a *Joomla* page, like this:
<? $user =& JFactory::getUser(); ?>
<a href="http://www.mysite.com/nonjoomla.php?userid=<? echo $user->get('id'); ?>">
That writes a querystring that will hand a Joomla variable over to a non-Joomla script.
If you have too many variables to hand over like this, write a form with hidden inputs that you populate and have it submit to the non-Joomla script when the user hits the button.
And then when you get to the non-Joomla page you can extract the userid from the querystring or form in normal php fashion and do whatever you like with it.
If you're really determined your script can't run inside of Joomla, you have to "get" that Joomla variables are not going to be accessible unless you specifically hand them over. So you need to write a URL for the user on a *Joomla* page, like this:
<? $user =& JFactory::getUser(); ?>
<a href="http://www.mysite.com/nonjoomla.php?userid=<? echo $user->get('id'); ?>">
That writes a querystring that will hand a Joomla variable over to a non-Joomla script.
If you have too many variables to hand over like this, write a form with hidden inputs that you populate and have it submit to the non-Joomla script when the user hits the button.
And then when you get to the non-Joomla page you can extract the userid from the querystring or form in normal php fashion and do whatever you like with it.
-
- Joomla! Apprentice
- Posts: 26
- Joined: Fri Jan 11, 2008 7:38 am
Re: How to get user id
Hi luis,luisfgf wrote:Hi,
Anyone can help me with de complet code for extract the user id or user name in the joomla 1.5 with the external scripts.
Thanks,
LF
the only way to do this things, you can using Wrapper link method at Joomla 1.5.7. I have tested this from my several joomla website.
But, first things to do is you must read this :
http://forum.joomla.org/viewtopic.php?f=304&t=343435
NB : I have tested several times using JFactory class like anyone mention above, but it's only giving "blank page" result. So I using Wrapper link method.. and it works and run properly..
Cheers,
Sonny_S
- TheMick07
- Joomla! Apprentice
- Posts: 19
- Joined: Thu Oct 23, 2008 7:00 pm
Re: How to get user id
I have the same problem when loading up 1.0.15 after already having 1.0.5jaguas wrote:Hello.
I have a form in a .php file in the same server of joomla but in another database.
I need to insert the username in the table.
With this code:
$user_joomla =& JFactory::getUser();
$usr_username = $user_joomla->get('username');
I get this error:
Class 'JFactory' not found
How can I solve this?
-
- Joomla! Apprentice
- Posts: 5
- Joined: Wed Nov 19, 2008 7:42 am
Re: How to get user id
it should be helpful:
http://dev.joomla.org/component/option, ... tableuser/
http://dev.joomla.org/component/option, ... tableuser/
http://beachrealestateagents.com/ Myrtle Beach Real Estate
http://www.aptas.net/ Telephone Answering Service
Signature rules - Literal URL's Only.
http://www.aptas.net/ Telephone Answering Service
Signature rules - Literal URL's Only.
-
- Joomla! Apprentice
- Posts: 15
- Joined: Thu Feb 12, 2009 1:11 pm
Re: How to get user id
Hi all, a question very similar...
I've added a filed in the jos_users table...
there's a way to get the field value I've added?
somothing like: $user->my_field;
tnx a lot!
I've added a filed in the jos_users table...
there's a way to get the field value I've added?
somothing like: $user->my_field;
tnx a lot!
-
- Joomla! Fledgling
- Posts: 1
- Joined: Fri Mar 20, 2009 3:39 pm
Re: How to get user id
I use this code to get id from user
but in my new server i can get the id but i recive this wornnigs:
Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/winbetpt/public_html/casas/teste.php:10) in /home/winbetpt/public_html/libraries/joomla/session/session.php on line 423
Warning: Cannot modify header information - headers already sent by (output started at /home/winbetpt/public_html/casas/teste.php:10) in /home/winbetpt/public_html/libraries/joomla/session/session.php on line 426
i can don't recive this wornnings
Code: Select all
define( '_JEXEC', 1 );
define('JPATH_BASE', dirname(__FILE__) );
define( 'DS', DIRECTORY_SEPARATOR );
require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' );
require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' );
$mainframe =& JFactory::getApplication('site');
$mainframe->initialise();
$mainframe->route();
$user =& JFactory::getUser();
print_r($user);
but in my new server i can get the id but i recive this wornnigs:
Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/winbetpt/public_html/casas/teste.php:10) in /home/winbetpt/public_html/libraries/joomla/session/session.php on line 423
Warning: Cannot modify header information - headers already sent by (output started at /home/winbetpt/public_html/casas/teste.php:10) in /home/winbetpt/public_html/libraries/joomla/session/session.php on line 426
i can don't recive this wornnings
-
- Joomla! Fledgling
- Posts: 1
- Joined: Mon Mar 23, 2009 10:12 am
Re: How to get user id
Hello everybody,
Now you can easily use member id on a non joomla page. Add the below code on index.php
It'll create a cookie of the user who has logged in..... and you can easily access this cookie on a non joomla page. using the below code
Now you can easily use member id on a non joomla page. Add the below code on index.php
Code: Select all
session_start();
$user =& JFactory::getUser();
$umsrf = $user->get('id');
setcookie("userid_m",$umsrf, time()+840);
Code: Select all
$u_id = $_COOKIE["userid_m"];