Q:

How to create a cookie to store the 5 last visited web pages in my domain? 

What I need is to create a javascript cookie to store something like a local database where when somebody visits a web page and then another (allways under the same domain), that person can see the last web pages from the site, like a history from your web browser. 
Example:
Someone visits www.domain.com/webpage1.html then the same person visits www.domain.com/webpage2.html.  Three days later that person visits www.domain.com, but that person want to know which pages he visited the day after that? 

A:

You can set the cookie in Javascript, as explained here:
http://www.w3schools.com/js/js_cookies.asp
You can add your new page to that cookie (by adding window.location.href to it) and keeping a space-separated string value in your cookie, something like
"domain.com/page1.html domain.com/page2.html domain.com/page3.html"
Then, you could use PHP to get that cookie, and explode it at its spaces, to get the latest URLs, and print them in your page. 
Of course, you should find a way in Javascript to only keep 5 URLs, so that your cookie doesn't grow extremely large.  For example, you can get the cookie value, split that into an array, and then only keep the last 5 values in the array.  That shouldn't require much code, and you can also use another cookie to select how many pages to keep in history :)
Hope this helps.