Read up on sessions in PHP manual. They give you plenty of examples. Here's the short version:
- The login form will get the data
<form method="post" action="login.php">
<input type="text" name="user">
<input type="password" name="pass">
<input type="submit" name="submit">
</form>
- The login script will start the session
<?php
//Start the session
session_start();
//Get the session ID
$sid = session_id();
/* The code verifies the username and password
I'm assuming that these lines exist:
$user = $_POST["user"];
$pass = $_POST["pass"];
*/
//If the login is successfull, register what you need with the session
$_SESSION["logged_in"] = true;
...
?>
Then decide how you want to pass the session ID. In the code above it is stored in the $sid variable. PHP has mechanism for doing it automatically. I prefer to do it manually. You can do it through the URL or via a cookie. It's up to you.
If you're using the PHP mechanism, then all you need to do is call session_start() at the top of the line. If you're passing the ID manually, then you can use the following code at the top of all your scripts:
<?php
/* code to extract your session ID goes here. I'm assuming it'll end up in $sid */
//Set the session ID
session_id($sid);
//And start the session
session_start();
/* Now you can use your stored $_SESSION vars */
...
?>
Hope this helps. If all else fails, RTFM some more 🙂