Well, that's easy enough to do if you use MySQL as your backend with an auto_incremented column for the user id.
Take this example:
<?php
if(isset($_POST['login']))
{
include "config.php";
// Adding slashes to the username and checksuming the pass.
$_POST['user'] = addslashes($_POST['user']);
$_POST['pass'] = md5($_POST['pass']);
$sql = "SELECT * FROM user WHERE password = '". $_POST['pass'] . "' AND username = '" . $_POST['user'] . "'";
$result = mysql_query($sql) or die ("Couldn't execute the query.");
if(mysql_num_rows($result) == 0)
{
echo "Sorry, your username and password didn't match. Please click <a href=\"login.php\">here</a> and try again.";
exit;
}
while($row = mysql_fetch_array($result))
{
$_SESSION['username'] = $row['username'];
$_SESSION['password'] = $row['password'];
$_SESSION['id'] = $row['id'];
}
echo "Welcome back " . $_SESSION['username'] . ". You're unique Id is ".$_SESSION['id'].". You have successfully logged in." ;
}
else
{
?>
<form action="login.php" method="post">
Username: <input type="text" name="user"><br>
Password: <input type="password" name="pass"><br><br>
<input type="submit" value="Login" name="login">
</form>
<?php
}
?>
So, as long as you're calling session_start(); at the top of the pages that you need the unique id for, it will always be available.
You can then insert it into the table for your shopping cart/inventory thing/whatever it is you're building.
Keep in mind that this example is rudimentary, and more security would probably be needed.