I'm developing a Scrap app to extract some information from a sit. To get that information I have to be logged in to that site.

So I use Http post and pass the data needed for login using FormData and log in successfully, so I can browse the private content of that site.

My question Is: "How can I tell if the user is logged in?". What is the simple way to do that using session cookies or something like that?

I'm currently checking the connection by sending an Http Get Request to a Url that I know is available to registered users.

So before I try to login again, I use this method "isLoggedIn" to check the connection. But it is not perfect, I mean, it seems a kind o tricky and not the best way to do that.

1 Answer 1


Instead of the pessimistic approach (check before every access) you might want to use an optimistic approach: just access the URLs you want, and if you get a HTTP 403 error you know that your authentication isn't valid anymore, so you have to re-login. Depending on your access patterns this might be more efficient. If you have long pauses between accesses (on the order of half hours or more) checking might still be reasonable.

Note that if the web site offers no API but only browser access the owners might not permit automated access, and regardless of the method that you're using might be able to identify your app as a bot and block the account, so you should probably check if and under what conditions automated access will be accepted.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.