⊗ppPmAuSUI 419 of 447 menu

Adding User Id to Session

Suppose that in addition to the authorization mark, we would also like to write his id to the session.

In this case, we can get it using the function mysqli_insert_id. This function gets the id of the last record inserted in this script, which is exactly what we need.

Let's implement it:

<?php if (!empty($_POST['login']) and !empty($_POST['password'])) { $login = $_POST['login']; $password = $_POST['password']; $query = "INSERT INTO users SET login='$login', password='$password'"; mysqli_query($link, $query); $_SESSION['auth'] = true; $id = mysqli_insert_id($link); $_SESSION['id'] = $id; // writing id to the session } ?>

During registration, also write the user's id to the session.

English
AfrikaansAzərbaycanБългарскиবাংলাБеларускаяČeštinaDanskDeutschΕλληνικάEspañolEestiSuomiFrançaisहिन्दीMagyarՀայերենIndonesiaItaliano日本語ქართულიҚазақ한국어КыргызчаLietuviųLatviešuМакедонскиMelayuမြန်မာNederlandsNorskPolskiPortuguêsRomânăРусскийසිංහලSlovenčinaSlovenščinaShqipСрпскиSrpskiSvenskaKiswahiliТоҷикӣไทยTürkmenTürkçeЎзбекOʻzbekTiếng Việt
We use cookies for website operation, analytics, and personalization. Data processing is carried out in accordance with the Privacy Policy.
accept all customize decline