Jump to content

[SOLVED] What would be better?


ballhogjoni

Recommended Posts

I have a script that tests which country a site visitor is from. If the visitor is from a country that I don't allow to view my site, then the script will die.

 

Would it be better to run this script each time a visitor goes from one page to another, or should I start a session and based off that session allow access to my site?

 

I hope that made sense.

Link to comment
https://forums.phpfreaks.com/topic/126500-solved-what-would-be-better/
Share on other sites

Sessions are kept persistent by the user. If they really wanted to, they can delete the session cookie forcing a new session to start.

 

I wouldn't bother. You could use both, checking the session, then checking the IP but consider this 'best-case' situation.

 

You have 1000 visitors... 5 of them are banned. For those 5, they keep the session cookie.

 

Your script checks for the session, and detects it. You don't have to poll the database to check if the user is banned - You save some processing time. This happens 5 times.

 

Your script checks for the session, and it doesn't exist. You check the database to see if the user should be banned. It comes up false. This happens 995 times.

 

As you can see.. only .1% of your user base is banned, and now you're forcing the vast majority to perform 2 checks instead of 1. You're better off with only a single check, as the time saved not having to check the banned user is probably lost in having to run multiple checks in legitimate users.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.