?
avatar AiswaryaShivan
AiswaryaShivan
3 Feb 2017

The issue is happening when a user logs in using app. While accessing pages multiple session of same user is creating and is listed multiple times in logged - in users. For app we are using separate API functions which are written in same joomla project used for web but APIs also use some core functions of joomla. How can we prevent the creation of multiple sessions.

Expected result

Only one session need to be added while login from APP

Actual result

Multiple sessions are created

System information (as much as possible)

Testing on
Joomla! Version Joomla! 3.3.6 Stable [ Ember ] 01-October-2014 02:00 GMT
Joomla! Platform Version Joomla Platform 13.1.0 Stable [ Curiosity ] 24-Apr-2013 00:00 GMT

Additional comments

Please help
Below given is the API function, while this API is accessed new session entries are getting added to 'tbl_session' table with the same user details who has logged in already. Thus multiple entries of same user is created in logged in users.

public function display($cachable = false, $urlparams = false) {
global $apitoken;
if(empty($apitoken['user_id'])){ echo json_encode(array('status'=>'error','message'=>'Invalid token.')); exit; }
$sub_profile_id=$_GET['sub_profile_id'];
if(!empty($_GET['laststreamid'])){
$streamid=$_GET['laststreamid'];
$filter=$_GET['filter'];
$filterValue = $_GET['value'];
$acti=$this->ajaxGetOlderActivities($streamid, $filter, $filterId, $filterValue,$sub_profile_id);
} else{
$acti=$this->showLatestActivities($sub_profile_id);
}

    $db = JFactory::getDbo();       
    foreach($acti as $k=>&$act1){  
        $cuser = CFactory::getUser($act1->actor);           
        $pos = strpos($cuser->getThumbAvatar(), 'components');
        if ($pos === false) {
            $act1->avatar=$cuser->getThumbAvatar();
        } else{
            $act1->avatar='http://'.$_SERVER['SERVER_NAME'].$cuser->getThumbAvatar();
        }

       if(!empty($act1->favicon)){
        $favi=explode('components',$act1->favicon);
        $sciptname=rtrim($_SERVER['SCRIPT_NAME'],'index.php/');
        $act1->favicon= 'http://'.$_SERVER['SERVER_NAME'].$sciptname.'/components'.$favi[1];            
       } else{
        $act1->favicon='';
       }

        $db = JFactory::getDbo();
        $title = $act1->title;	
        $post_ids = $act1->id;      

        if(!empty($post_ids)){ 

            $tag_ids = 'SELECT id , event_id , eve_cat_id FROM'  . $db->quoteName( '#__community_activities_tag' ) . 'WHERE '.$db->quoteName( 'activity_id' ).'='.$post_ids.' AND '.$db->quoteName( 'group_tag' ).'= 0 ORDER BY id DESC LIMIT 1';                    
            $db->setQuery($tag_ids);
            $tag_id = $db->loadObjectList();
              
            if(!empty($tag_id)){
                $act1->tagEventid =$tag_id[0]->event_id;
            } else{
                $act1->tagEventid='';
            }    

            $sql = 'SELECT DATE_FORMAT(user_date, "%M %D %Y") as user_date,eve_cat_id,for_kudos,created,user_date,sevice_hours,sub_title,FB_share_status,access FROM '  . $db->quoteName( '#__community_activities' ).' WHERE '.$db->quoteName( 'id' ).'='.$post_ids;
            $db->setQuery($sql);         
        
            $category_ids = $db->loadObjectList();
            $act1->eve_cat_id = $category_ids[0]->eve_cat_id;
            $act1->service_hours=$category_ids[0]->sevice_hours;
            if($category_ids[0]->user_date != '0000-00-00'){                
                $old_date_timestamp = strtotime($category_ids[0]->user_date);
                $new_date = date('F j Y', $old_date_timestamp);
                $act1->date_of_accomplishment = $new_date;
            } else{
                $act1->date_of_accomplishment = '';
            }
            if($act1->verb=="announcement") {   $act1->sub_title = ""; }else{
            $act1->sub_title = $category_ids[0]->sub_title;
	}   

            $sqls = 'SELECT * FROM'  . $db->quoteName( '#__community_events_category' ) . 'WHERE '.$db->quoteName( 'id' ).'='.$category_ids[0]->eve_cat_id;
            $db->setQuery($sqls);
            $event_category_details = $db->loadObjectList();
        
            if(!empty($event_category_details[0]->icon)){
            $act1->event_category_icon = JURI::base().'administrator/components/com_community/assets/img/'.$event_category_details[0]->icon;
            } else{
                $act1->event_category_icon='';
            }            
            $act1->event_category_name = $event_category_details[0]->name;

       
            $activity = new CActivity($act1);
        
            $act1->permission = $activity->getPermission($act1->cid);
            $user = $activity->getActor();

            $act1->displayname=$user->getDisplayName();    
    		if($act1->displayname=="a Guest"){
    		 unset($acti[$k]);
    		}   
            if($act1->app=='groups'){                    
                $act1->title=str_replace("{actor}",$act1->displayname,strip_tags($act1->title));
            } elseif($act1->app=='friends.connect'){                    
                $act1->actor_details->name=$cuser->name;
                $act1->actor_details->email=$cuser->email;
                $cuser11 = CFactory::getUser($act1->target);
                $act1->target_details->name=$cuser11->name;
                $act1->target_details->email=$cuser11->email;                   

            } else{
                $act1->title=strip_tags($act1->title);    
            }


            if(!empty($act1->album)){                    
          
                $act__album=$act1->album;                    
                unset($act1->album);
                foreach($act__album as $key=>$act_album){
                   
                    $act1->album[$key]->id=$act_album->id;
                    $act1->album[$key]->albumid=$act_album->albumid;
                    $act1->album[$key]->creator=$act_album->creator;
                    $act1->album[$key]->caption=$act_album->caption;
                    $act1->album[$key]->published=$act_album->published;
                    $act1->album[$key]->permissions=$act_album->permissions;
                    $act1->album[$key]->created=$act_album->created;
                    $act1->album[$key]->original=$act_album->original;
                    $act1->album[$key]->filesize=$act_album->filesize;
                    $act1->album[$key]->hits=$act_album->hits;

                    $sciptname=rtrim($_SERVER['SCRIPT_NAME'],'index.php');
                    $act1->album[$key]->thumbnail='http://'.$_SERVER['SERVER_NAME'].$sciptname.$act_album->thumbnail;
                    $act1->album[$key]->image='http://'.$_SERVER['SERVER_NAME'].$sciptname.$act_album->image;
                    
                    $act1->album[$key]->params =$act_album->params;               
                    
                    $data1 = json_decode($act1->album->params, true);
                    if(!empty($data1['thumbnail'])){ 
                        
                        $data1['thumbnail']='http://'.$_SERVER['SERVER_NAME'].$sciptname.$data1['thumbnail'];
                        //$data1['photo']=$_SERVER['SERVER_NAME'].$sciptname.str_replace('thumb_','',$data1['thumbnail']);
                        $data1['photo']=str_replace('thumb_','',$data1['thumbnail']);
                        $act1->album[$key]->params=json_encode($data1);
                    }

                }
                
                
            }                               
            $act_params=$act1->params;
           
            $json_string = stripslashes($act_params);
            $data1 = json_decode($json_string, true);
            $act1->action=$data1['action'];

           
            if($act1->app=='videos.linking'){

                $json_string = stripslashes($act_params);
                $data1 = json_decode($json_string, true);
                $act1->video->videourl=$_SERVER['SERVER_NAME'].$_SERVER['SCRIPT_NAME'].'/'.$data1['video_url'];
                $act->video->style=$data1['style'];
	            $video1 = JTable::getInstance('Video', 'CTable');
                $video1->load($act1->cid);               
            if(!empty($video1->video_id)){
            $act1->video->youtubelink="https://www.youtube.com/watch?v=".$video1->video_id;//$video1->path;
	}else{
	$act1->video->youtubelink="";
	}
            }
            if($act1->app=='events' && $act1->action=='events.create' ){
            $event = JTable::getInstance('Event', 'CTable');
            $event->load($act1->eventid);
            $this->set('event', $event);
          
                $act1->event->id=$event->id;
                $act1->event->parent=$event->parent;
                $act1->event->catid=$event->catid;
                $act1->event->contentid=$event->contentid;
                $act1->event->type=$event->type;
                $act1->event->title=$event->title;
                $act1->event->summary=$event->summary;
                $act1->event->description=strip_tags($event->description);
                $act1->event->location=$event->location;
                $act1->event->creator=$event->creator;
                $act1->event->startdate=$event->startdate;
                $act1->event->enddate=$event->enddate;
                $act1->event->permission=$event->permission;
                $act1->event->avatar=$event->avatar;
                $act1->event->thumb =$event->thumb;
                $act1->event->invitedcount =$event->invitedcount;
                $act1->event->confirmedcount =$event->confirmedcount;
                $act1->event->declinedcount =$event->declinedcount;
                $act1->event->hits =$event->hits;
                $act1->event->published =$event->published;
                $act1->event->wallcount =$event->wallcount;
                $act1->event->ticket =$event->ticket;
                $act1->event->allowinvite =$event->allowinvite;                   
            }                
        }
    }


 
    unset($act1);
    if(!empty($acti)){ foreach($acti as &$actii){
       if($actii->verb=="announcement" || $actii->displayname=="a Guest") {  
	$actii->content= ""; 
	}
	else{
            $actii->content= strip_tags($actii->content);
	}
    } 
    } 
   
    $acti=array_values($acti);
    echo json_encode($acti); exit;       
}
avatar AiswaryaShivan AiswaryaShivan - open - 3 Feb 2017
avatar joomla-cms-bot joomla-cms-bot - change - 3 Feb 2017
Labels Added: ?
avatar joomla-cms-bot joomla-cms-bot - labeled - 3 Feb 2017
avatar AiswaryaShivan AiswaryaShivan - edited - 3 Feb 2017
avatar tonypartridge
tonypartridge - comment - 4 Feb 2017

Hello,

This looks like. Support question rather than a Joomla! Issue. Please use the Joomla! Forums for help.

Re the issue it sounds like your not checking if the user is logged in before starting a new session.

avatar zero-24
zero-24 - comment - 4 Feb 2017

Please provide more info about the app? I expect a issue in that app like @tonypartridge also noticed so this is nothing the core can fix.

avatar AiswaryaShivan
AiswaryaShivan - comment - 8 Feb 2017

Any updates ?
@tonypartridge We are not creating any session in api function..

avatar AiswaryaShivan AiswaryaShivan - change - 8 Feb 2017
The description was changed
avatar AiswaryaShivan AiswaryaShivan - edited - 8 Feb 2017
avatar AiswaryaShivan AiswaryaShivan - change - 8 Feb 2017
The description was changed
avatar AiswaryaShivan AiswaryaShivan - edited - 8 Feb 2017
avatar AiswaryaShivan AiswaryaShivan - change - 8 Feb 2017
The description was changed
avatar AiswaryaShivan AiswaryaShivan - edited - 8 Feb 2017
avatar tonypartridge
tonypartridge - comment - 8 Feb 2017

Hello @AiswaryaShivan , I'm not sure what you want. This isn't a core issue and I'm sorry but this isn't a support forum either.

I'd suggest you debug your code through an IDE and look for what it matching the mechanism for multiple sessions given when you login with Joomla! you don't get multiple sessions.

avatar brianteeman
brianteeman - comment - 10 Mar 2017

This is for a very old and unsupported version of Joomla and should be closed - Support should be given on the forum @zero-24

avatar zero-24 zero-24 - change - 10 Mar 2017
The description was changed
Status New Closed
Closed_Date 0000-00-00 00:00:00 2017-03-10 12:57:54
Closed_By zero-24
avatar zero-24 zero-24 - close - 10 Mar 2017

Add a Comment

Login with GitHub to post a comment