To respond with better alternatives, I'd like to point you to Stormpath's Auth article and a related StackOverflow question. The Stormpath article has some big name options if you don't like writing this sort of code (I love it.) and the related question has a great answer with examples I'd have stolen otherwise.
I'd love to quote you some snippets to clear things up, but there's a zillion ways to handle implementations. The basic flow is this:
Client passes credentials to Server
Server Authenticates credentials
Server generates a token (UUID, random string, whatever)
Server replies with the requested info and token
Client sends token with the next request
Server matches token to authenticated session
Repeat 4-6 until the session is expired (Logout or timeout)
My own implementations usually continue differently to prevent some other security issues:
Server deprecates the token used by the request
Server generates a new token
Server replies with requested info and new token
Repeat steps 5-9 until the session is expired (Logout or timeout)