Welcome Guest, Not a member yet? Register   Sign In
Detecting a users first visit to a website using codeigniters session library
#1

[eluser]Bainzy[/eluser]
As above really people, is there any way i can detect if its the users first visit to my site, and if so show them a message ?

Bit stuck, have done a search but nothing came up.

Chris
#2

[eluser]verynewtothis[/eluser]
How about using cookies for this?
#3

[eluser]jsfmills[/eluser]
Codeigniter session problems is resolved for internet explorer but still create problem in WAP.I'm pretty new to codeigniter, but not new to frameworks.I've tried them all and I find codeigniter to be the best overall.Keywords in the URL now have only a very minor impact on the search results, if at all.
#4

[eluser]bretticus[/eluser]
No need to use sessions. Sessions are not really meant for this kind of thing anyway. Sessions store user-specific data for some length. In other words, they allow a website to keep state with any given browser using the stateless protocol http. This is the kind of thing that allows the webserver to keep you logged into a secure area of the website (you get the picture no doubt.) CodeIgniter Sessions work by storing either a random key or a random key plus the data in a cookie. This key, or session id, is returned each time your browser makes a new request. Sessions are meant to die after a set amount of time. So even if your cookie never expires, the Session mechanism at the server will ignore expired sessions because its internal registry of current sessions has been cleansed. This is exactly why sessions are a poor choice for what you need.

First time access is another concept altogether. You are concerned with nothing more about the end-user, other than if this is the first visit. @verynewtothis is right to suggest cookies. In fact, this problem is solved by checking for a cookie when someone comes to your Website. If it's not there, then show your message (but be sure to add the cookie so the next time you check for it, it will be there.) If it is there, then update the expiration date (add another year to the cookie expiration, for example. See Cookie Helper.) Also, if there, then don't show the message.

This is NOT a perfect solution since persons can use different browsers or clean their cookies. It's probably good enough if you say somehting like, "It appears this is *probably* your first visit. Welcome..."

Another approach is to record the IP address of everyone that enters your website. You could store the IP's in database, for example. Then, simply check for the IP, if it's not there, show the message and be sure to record the new IP in the database. Also, not a perfect solution because of DHCP leased IP's and Web proxy.

In fact, the only rock solid way would be to require registration/login on your website. Probably not feasible though.

Good luck!
#5

[eluser]Clooner[/eluser]
I use something like this.
Code:
function isNew()
{
    $CI = & get_instance();
    $this->_key = $CI->session->userdata('visitor_key');
    if (!$this->_key)
    {
        $this->_key = uniqid();
        $CI->session->set_userdata('visitor_key', $this->_key);
        return true;
    }
    return false;
}
You will need to load the session library and make sure your settings are correct. I have this in a library but you could put it also in a (MY_)Controller with minor adjustments!
#6

[eluser]Bainzy[/eluser]
Thank you for the replys on this one, i dont know why i was thinking sessions when i did mean cookie ( half asleep at the time ).

I will look into both clooner's and bretticus's ideas and see which one fits my needs and works best. It litrally is to pop up a message saying something along the lines of "Hey, we notice this is your first visit. Welcome to the site why not register and stick around ..etc etc"

Thanks again guys !




Theme © iAndrew 2016 - Forum software by © MyBB