开发者

What's best way to show the same results to a user based on their postcode?

I'm developing a website where a user can search for 'something' near their location that they enter (in the UK). There maybe say up to 10+ matching results, but the client only wants 3 results to be shown at any one time. Because each 'something' is paying the same amount to be listed, each 'something' should have the same chance of being displayed...and these results should not change each time the same user makes the search..

I'm thinking use the users 开发者_如何学Cpostcode as a seed, and randomly select 3 results out of the matching list. Would this be a good way of achieving this? what are my other options?


You could use the last two octets of the IP address that initiated the request as a random seed. That would give you a somewhat evenly-distributed 65,536 possible seed values. I would then set their IP address back to them in a cookie in case they are connecting through a network that randomizes the external address they connect from. You'd use the value of the cookie if it's present, otherwise use their actual address.

I say the last two octets instead of the first two since using the first two will cause e.g. all users of the same local ISP to wind up receiving the same results, and I'd expect the last two octets to be much more evenly distributed by your users.

Note that for e.g. companies or universities that route all traffic through one address, all of the users in that institution would see the same results with this approach.

If you are not adverse to the idea of cookies, set a 1-year or so cookie that renews with each visit, containing 64 bits or so of random garbage. Then use that as your seed.


If you want it to be random which items they get shown, why not just use PHP's rand function to generate a random seed? Once their seed has been generated, you can save a cookie with the value. When loading the page, check to see if the cookie exists. If it does, use the value in the cookie; if it doesn't, then regenerate the random number and create a new cookie. It wouldn't work if the user clears their cookies every time they close the browser, but most people don't do that.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜