Using a $_SESSION or making a cookie. But you shouldn't just store your database connection details into a session (and certainly not into a cookie), that is kinda insecure.
Rather design something like this (Okay, some pseudo code!):
For registration of new users:
<!--Registration page!-->
<form>
<input id=name>
<input id=password>
</form> <!--After submit, link to input-user-page!-->
//input-user-page
$name = $_POST['name']
$pass = $_POST['password']
query_insertuser($name, $pass) //make some mysql code from this
For login existing users:
<form>
<input id=name>
<input id=password>
</form> <!--After submit, link to user-validation-page!-->
//User-validation-page
$name = $_POST['name']
$pass = $_POST['pass']
$result = query_validation($name, md5( $pass )) //compare name and password with those in the database (this is all psuedo code!!)
if (result == true) { //user validated! (of course, this is pseudo code too)
$_SESSION['userId'] = $name //We'll keep track of this user now
}
else {
header("Location: index.php") //no validation, be gone!
}
Every new page should call this code:
//function to be called in every page that requires login
if (!empty($_SESSION['userId')) { //user exists
echo("Let's drink a beer mate!");
}
else {
header("Location: index.php") //not validated, be gone!
}