Google Chrome not getting data $user->id

General questions relating to Joomla! 3.x.

Moderator: General Support Moderators

Forum rules
Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting.
Forum Post Assistant - If you are serious about wanting help, you should use this tool to help you post.
Windows Defender SmartScreen Issues <-- please read this if using Windows 10
Locked
User avatar
donnan
Joomla! Ace
Joomla! Ace
Posts: 1487
Joined: Sat Jun 30, 2007 1:23 am
Location: Sydney, Australia
Contact:

Google Chrome not getting data $user->id

Post by donnan » Wed Jun 27, 2018 7:12 pm

Anyone had the problem of Google Chrome not retreiving the data from a call for user information?

I have this right at the top of my page to get the current logged in users id and username.

Code: Select all

$user = JFactory::getUser();
$uname = $user->username;
$ri = $user->id;

User avatar
toivo
Joomla! Master
Joomla! Master
Posts: 13957
Joined: Thu Feb 15, 2007 5:48 am
Location: Sydney, Australia

Re: Google Chrome not getting data $user->id

Post by toivo » Wed Jun 27, 2018 7:36 pm

That PHP code is run in the server and it is browser agnostic. Is the code used in a component or a module?
Toivo Talikka, Global Moderator

User avatar
donnan
Joomla! Ace
Joomla! Ace
Posts: 1487
Joined: Sat Jun 30, 2007 1:23 am
Location: Sydney, Australia
Contact:

Re: Google Chrome not getting data $user->id

Post by donnan » Wed Jun 27, 2018 7:41 pm

I have the code in a wrapper/module right at the very top of the page. It works in all the other browsers accept chrome.

Code: Select all

<?php

if (!defined('_JEXEC'))
{
    // Initialize Joomla framework
    define('_JEXEC', 1);
}

// Load system defines
if (file_exists(dirname(__FILE__) . '/defines.php'))
{
    require_once (dirname(__FILE__) . '/defines.php');
}
if (!defined('JPATH_BASE'))
{
    define('JPATH_BASE', dirname(__FILE__));
}
if (!defined('_JDEFINES'))
{
    require_once JPATH_BASE . '/includes/defines.php';
}

// Get the framework.
require_once (JPATH_BASE . '/includes/framework.php');

$app = JFactory::getApplication('site');
$app->initialise();

$user = JFactory::getUser();
$uname = $user->username;
$ri = $user->id;
$utables = $user->tables;
$db = JFactory::getDBO();


?>
<html>

User avatar
donnan
Joomla! Ace
Joomla! Ace
Posts: 1487
Joined: Sat Jun 30, 2007 1:23 am
Location: Sydney, Australia
Contact:

Re: Google Chrome not getting data $user->id

Post by donnan » Wed Jun 27, 2018 7:47 pm

the funny thing is, further down the page there is calls to a few tables and they work fine, but aren't using the $user_id I need.

User avatar
donnan
Joomla! Ace
Joomla! Ace
Posts: 1487
Joined: Sat Jun 30, 2007 1:23 am
Location: Sydney, Australia
Contact:

Re: Google Chrome not getting data $user->id

Post by donnan » Wed Jun 27, 2018 7:50 pm

it's the wrapper/module I am using in which I place the URL to the page.

User avatar
toivo
Joomla! Master
Joomla! Master
Posts: 13957
Joined: Thu Feb 15, 2007 5:48 am
Location: Sydney, Australia

Re: Google Chrome not getting data $user->id

Post by toivo » Wed Jun 27, 2018 8:00 pm

Are you running a Command Line Interface (CLI) script inside an iframe? That is rather unusual. It would be better to create an installable module instead and assign it to a module position.
Toivo Talikka, Global Moderator

User avatar
donnan
Joomla! Ace
Joomla! Ace
Posts: 1487
Joined: Sat Jun 30, 2007 1:23 am
Location: Sydney, Australia
Contact:

Re: Google Chrome not getting data $user->id

Post by donnan » Wed Jun 27, 2018 8:01 pm

It's basically a webpage inside the wrapper...I don't have the knowledge to created a module. :(

User avatar
donnan
Joomla! Ace
Joomla! Ace
Posts: 1487
Joined: Sat Jun 30, 2007 1:23 am
Location: Sydney, Australia
Contact:

Re: Google Chrome not getting data $user->id

Post by donnan » Wed Jun 27, 2018 8:10 pm

Another strange thing was that this was working, then a number of my users started having problems with it. I wonder if Chrome did an update that stopped it working?

User avatar
toivo
Joomla! Master
Joomla! Master
Posts: 13957
Joined: Thu Feb 15, 2007 5:48 am
Location: Sydney, Australia

Re: Google Chrome not getting data $user->id

Post by toivo » Wed Jun 27, 2018 8:31 pm

That is very likely because Chrome has introduced a number of restrictions to improve security.

Simple modules are straight forward to develop. You could start by cloning an existing module, modifying it, changing the manifest file to use a different name and then packaging the files into an installable .zip file.
Toivo Talikka, Global Moderator

User avatar
donnan
Joomla! Ace
Joomla! Ace
Posts: 1487
Joined: Sat Jun 30, 2007 1:23 am
Location: Sydney, Australia
Contact:

Re: Google Chrome not getting data $user->id

Post by donnan » Wed Jun 27, 2018 9:00 pm

Funny you say that.

I just cloned the mod_wrapper and gave it a name mod_pif_wrapper and then added some code to grab the logged in user id and attach it to the end of the url placed in the wrapped URL field but even it won't share the $user->id.

Code: Select all

$url = $params->get('url');

//I added these two lines to concantenate the user id on the end of the url in the wrapper....it still won't parse the user-id.

		$url .= "?uid=";
		$url .= $user->id;
		
There must be some way to parse the user-id to this url in the wrapper! for a chrome fix.

User avatar
toivo
Joomla! Master
Joomla! Master
Posts: 13957
Joined: Thu Feb 15, 2007 5:48 am
Location: Sydney, Australia

Re: Google Chrome not getting data $user->id

Post by toivo » Thu Jun 28, 2018 6:46 am

I do not get it, unless you are trying to pass in the URL a user id to a different site, presented inside an iframe, so that the user would get logged in somehow automatically?

It would help if you could explain using a top-down approach what the objective is and how you plan to get there.
Toivo Talikka, Global Moderator

User avatar
donnan
Joomla! Ace
Joomla! Ace
Posts: 1487
Joined: Sat Jun 30, 2007 1:23 am
Location: Sydney, Australia
Contact:

Re: Google Chrome not getting data $user->id

Post by donnan » Thu Jun 28, 2018 7:09 am

Up until yesterday members were able to use Chrome on the site and it worked fine. Today Chrome doesn't work yet any other browser is able to get the user->id info no problem.

I have a joomla site and I have a site I am building which is just basically a 1 page, which is a program where members participate together. I need each ones id's and usernames, that's it. So I wrapped that one page of php code and html in a Module wrapper so users could only access the page after they are logged in.

Seems strange how something as simple as parseing the user-id is so hard to get it from the <iframe to the page. The wrapper uses the url of the page to hold the page in the module.

After creating the cloned wrapper module it wouldn't even parse the user-id that way....I even hard coded the url into the helper.php file.....but for some reason the helper file couldn't get the user->id of that logged in user.

here is the code I added in the helper.php file.

Code: Select all

		$url = $params->get('url');

          //3 lines below added to get current logged in user->id and add it to the url
		$user = JFactory::getUser();
		$url .= "?uid=";
		$url .= $user->id;
Why this never worked has got me too...


Locked

Return to “General Questions/New to Joomla! 3.x”