Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6025545
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T04:18:58+00:00 2026-05-23T04:18:58+00:00

I have created a custom PHP script which uploads information submitted by a form

  • 0

I have created a custom PHP script which uploads information submitted by a form to a MySQL database. I would like to insert the user id from Joomla of the user who submitted the MySQL data.

To do this I have read that Joomla generates a session cookie while a user is logged into joomla. My hope is to be able to identify the matching cookies and then copy the joomla user id and update the value into the custom mysql database.

Here is what I have so far. It is not functioning properly, but it should give you an idea of the approach to my issue.

<?php
session_start();

//makes connection to databases
include_once "mysql-connect.php";       
if (isset($_SESSION['id'])) {
$id = $_SESSION['id'];   //I save the id in a session variable   
saveUserData($id);
// activeProfile is the name of the cookie used by Joomla/Jomsocial
} elseif (isset($_COOKIE['activeProfile'])) { 
$id = $_COOKIE['activeProfile'];
saveUserData($id);
} else {
$return_msg = "not_logged_in";
}

function saveUserData($id) {
// this is where I save the id in a session variable
$_SESSION['id'] = $id;   

$myConnJ = mysqli_connect("hostname","username","password","databasename") 
or die ("could not connect to joomla");
//query login info from Joomla
$sql = "SELECT * FROM jos_session WHERE id='".$id."'"; 
$result = mysqli_query($myConnJ, $sql) 
or die('ERROR: jos_user query failed for id = $id');
$row = mysqli_fetch_array($result);

echo $row;
// user data I need for charts is saved in session vars
$jom_id = $row['id'];           
$_SESSION['jom_id'] = $jom_id;

}
?>

I have tried a variety of echos to get the data to display but nothing is working. Ideally $jom_id would be the user id from the session data that I could insert into the custom database. I think this needs some development on the method of verifying the matched cookies.

One more thing, I was reading up on similar issues and there was the suggestion to use built in Joomla commands to access the Joomla session data. If you have insight onto how I could use these commands, please let me know. Here are some examples of the code:

define( '_JEXEC', 1 );
define('JPATH_BASE', dirname(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');

As always, thank you for any direction that you can provide. It is very much appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T04:18:59+00:00Added an answer on May 23, 2026 at 4:18 am

    Maybe I misunderstand what you are asking, for the retrieval of user id is pretty simple in Joomla. In order to get the information from the currently logged user you just acces the JFactory::getUser() method. No need to bother with sessions:

    $user = &JFactory::getUser();
    

    You now have an object containing all the infos you need:

    1. id – The unique, numerical user id. Use this when referencing the user record in other database tables.
    2. name – The name of the user.
    3. username – The login/screen name of the user.
    4. email – The email address of the user.
    5. password – The encrypted version of the user’s password
    6. password_clear – Set to the user’s password only when it is being changed. Otherwise, remains blank.
    7. usertype – The role of the user within Joomla!.
    8. gid – Set to the user’s group id, which corresponds to the usertype.
    9. block – Set to ‘1’ when the user is set to ‘blocked’ in Joomla!.
    10. registerDate – Set to the date when the user was first registered.
    11. lastvisitDate – Set to the date the user last visited the site.
    12. guest – If the user is not logged in, this variable will be set to ‘1’. The other variables will be unset or default values.

    You can get the id like $id = $user->id;

    I took the above informations in joomla! wiki: Accessing the current user object
    Api documentation of the JUser class: JUser.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created custom attributes for a category in my module's install script like
If have created a custom role within SqlServer which I added to the db__denydatareader
I have created a simple Asp.Net custom control which automatically combines all the correct
I like to create a file full of custom functions which I have made,
I have a custom php script that looks through text to find key phrases
I have a form that uses ajax to submit data to a mysql database,
I have created a Custom preference which has the following constructor public CoordinatesPreference(Context context,
I have created custom MembershipUser, MembershipProvider and RolePrivoder classes. These all work and I
I have created a custom dialog for Visual Studio Setup Project using the steps
I have created a small flash CS4 project that has a few custom components

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.