Answer the question
In order to leave comments, you need to log in
How to write the user's ip address to the database in Yii2 during registration?
How to write the user's ip address to the database in Yii2 during registration?
Answer the question
In order to leave comments, you need to log in
You can get the user's IP address from the application's Request object, for example:
Yii::$app->request->userIP
and then write it to your user model, save it, etc.
$model = new User(['ip' => Yii::$app->request->userIP]);
if ($model->load(Yii::$app->request->post()) && $model->save()) {
......
}
if ($model->load(Yii::$app->request->post()) && $model->validate()) {
$model->ip = Yii::$app->request->userIP;
$model->save(false);
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question