User identity missing with an Ajax call


I’m facing a strange problem: user identity are missing when an action is called by ajax, it’s considered as a guest.

I have this problem in Chrome, not in Firefox :mellow:


With what? :)

Show us some code, give us a sign …

in my JS file:


type: ‘POST’,

url: ‘../advertisement/checkremainclicks’,

dataType: ‘json’,

data: {id: idAd},

success: function(data) {


public function actionValidateclicks(){

	if (Yii::$app->request->isAjax){


			return 1;

		$visit = new Visit();

		$mem = Yii::$app->user->identity->login;

		$ad = $_POST['id'];


		$visit->member_login = $mem;

		$visit->advertisement_idadvertisement = $ad;

		$visit->ip = Yii::$app->request->userIP;

It returns 1 on chrome, but do the action on firefox

I tried also an absolute URL…

Try and read this:

Thank you a lot for the effort!

But this issue is not getting from a form, here is an example

is user logged in both browsers??

login detection is based on session and cookie.

so make sure that user is logged in chrome too.

I’m logged on both

Other members facing same issue.

try this in user component config:

‘user’ => [

        'class' => 'YOUR\USER\CLASS',

        'identityCookie'=>['name' => '_identity'],


and clear all cookies then try again

Probelm solved! :lol:

I changed

onclick="'<?= ''.$model->idadvertisement ?>','_blank');">


onclick="'<?= Url::to(['visit', 'ad' => $model->idadvertisement]) ?>','_blank');">

Seems that chrome omit SESSION when using absolute URL

Thank you all!

I think it happened because you open site with

url and link in ajax request with,

the cookie will set for domain without www and when you try to access domain with www prefix there is no cookie for session there.

Not at all!

I’m surfing with ‘www’

I even tried before to find the solution the cross domain property on JQuery, but didn’t solve it.

Use db base session that is no user identity problem will come.