What need is a login script which sets a cookie or starts a session for each user when they login, then when they are on viewprofile.php the approriate file or SQL record is loaded according to the cookie/session
However, if you aren't at all in the no about the code u are wanting to use i would advise about trying to embark on this kind of script first. Try doing some session or cookie tutorials and looking at code in the file libaries on this site.