• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to tell is this is a user's first visit?

#1
[eluser]FlashChilli[/eluser]
Hi everyone,

I'm new to CodeIgniter and I'm amazed how much faster I can develop PHP with it, I just have two questions.

1. Is there a way to tell if this page load is a user's very first visit to this website? (I'm using the sessions class and Redux Auth). I know that you would need to check if a cookie exists or not but, if it didn't then wouldn't it be created by the session class before your code is executed?

2. Oh dear, I've forgotten my second question. I'm sure I'll remember it soon... I hope : )

#2
[eluser]Yorick Peterse[/eluser]
Use a database, that's the only possible way of doing it. Simply store the IP address. When loading the page check to see if the user's ip is already in the database and you're done.

#3
[eluser]FlashChilli[/eluser]
Oh, I was hoping I wouldn't have to do that as the table could get pretty huge. It doesn't have to be perfect as I only want to count the number of unique visitors and total up how many are using certain browsers, so it's not too bad if some people are counted a few times. To be honest, I'd rather modify the sessions class than use a database but I'm not sure how to.

#4
[eluser]Yorick Peterse[/eluser]
[quote author="FlashChilli" date="1246832223"]Oh, I was hoping I wouldn't have to do that as the table could get pretty huge. It doesn't have to be perfect as I only want to count the number of unique visitors and total up how many are using certain browsers, so it's not too bad if some people are counted a few times. To be honest, I'd rather modify the sessions class than use a database but I'm not sure how to.[/quote]

You can't use the session class as it will expire eventually, unless you would set the expiration time to 1 year (31 536 000 seconds) or something like that.

#5
[eluser]jayrulez[/eluser]
[quote author="Yorick Peterse" date="1246831816"]Use a database, that's the only possible way of doing it. Simply store the IP address. When loading the page check to see if the user's ip is already in the database and you're done.[/quote]
there will be discrepancy in the case of sharedd ips

[quote author="FlashChilli" date="1246831607"]Hi everyone,

I'm new to CodeIgniter and I'm amazed how much faster I can develop PHP with it, I just have two questions.

1. Is there a way to tell if this page load is a user's very first visit to this website? (I'm using the sessions class and Redux Auth). I know that you would need to check if a cookie exists or not but, if it didn't then wouldn't it be created by the session class before your code is executed?

2. Oh dear, I've forgotten my second question. I'm sure I'll remember it soon... I hope : )[/quote]

You said you're using Redux Auth, correct? Is your question simply "how to tell if it's the user's first visit?" or do you want to check when the first time hte user logs in is?

#6
[eluser]richthegeek[/eluser]
Im probably missing something, but why wouldn't setting a cookie to expire in 50 years work in this case? It's worked fine for me before..

#7
[eluser]FlashChilli[/eluser]
[quote author="jayrulez" date="1246836539"]You said you're using Redux Auth, correct? Is your question simply "how to tell if it's the user's first visit?" or do you want to check when the first time hte user logs in is?[/quote]Their first visit, ever.

[quote author="richthegeek" date="1246837192"]Im probably missing something, but why wouldn't setting a cookie to expire in 50 years work in this case? It's worked fine for me before..[/quote]I guess I'll have to do that, although I thought it would have been easier to re-use the session one.

#8
[eluser]slowgary[/eluser]
Why not just use Google Analytics? It'll tell you things like that as well as much more. No sense in reinventing the circle.

#9
[eluser]Phil Sturgeon[/eluser]
I put a cookie check into the home-page here that just overrides itself on each page load incrementing its value 1 at a time. If its 5 or over, we don't show the big red banner any more.

If somebody clears their cookies then obviously they will show up as new again. Not much to be done about that.

#10
[eluser]Thorpe Obazee[/eluser]
cookies. Very much like what Phil does. People can share still share IPs.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.