add_membership() function not working in pages.

I was trying to add member from front end using add_membership() functions in my custom sign up form. The user is getting added to the membership in back end, but when i try to access the membership ( has_membership( ) ) from front end the user is not in that corresponding membership. Why is it so?