Remember a visitor with no cookies

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Vero44
Forum Newbie
Posts: 1
Joined: Sat Jan 22, 2011 6:57 am

Remember a visitor with no cookies

Post by Vero44 »

Hi. I have a small bit of php code (running on each page of my website) that remembers the user in a cookie. If the user has cookies turned off I want to be able to carry out an action that prevents this code from running again but allows it to run once only. I understand that session variables are turned off when cookies are turned off.

How can I achieve this? Here's my current code:

Code: Select all

if (isset($_COOKIE['xyz']))  //If my cookie IS set
{
//Do something
}

else //If visitor has no cookie
{

		//nested if

		If (not-sure-what-to-put-here) //If we have been here before
		{
		//Do something to prevent code running again
		} else {
		//code I want to carry out once only
		}
}
Thanks in advance!
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: Remember a visitor with no cookies

Post by social_experiment »

If the user doesn't use cookies it significantly lowers the ways to identify them. You could try checking the IP address (and the remote host name) but that's not a sure fire way to know if it's the same user.
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: Remember a visitor with no cookies

Post by John Cartwright »

Sessions are not disabled when cookies are disabled. Simply the session id is passed via the URL automagically (enabled via php.ini) whereas it is normally done through cookies transparently.
iballeat
Forum Newbie
Posts: 1
Joined: Sat Jan 22, 2011 4:50 pm
Location: Kyiv, Ukraine

Re: Remember a visitor with no cookies

Post by iballeat »

You can keep a log of visits, writing the ip of visitors and the date of renewal opportunities entrance. This will be your server cookies.
Post Reply