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!
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.
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
}
}
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
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.