Skip to main content
Inspiring
June 25, 2009
Answered

How do I prevent multiple registrants from overwriting each other's cookies?

  • June 25, 2009
  • 2 replies
  • 1047 views

Here’s the problem:

1 household, multiple users who don’t log on or off. They are learning different languages. They come to the site to register and the registration part works fine. But, because they don't properly logon and off, the cookies that are set by the first registrant are overwritten by the second and so on.  When someone returns to the site, the cookies set by the second or third registrant would take the 1st registrant to the wrong login page. Is there a standard solution for this (seemingly) obvious problem?

Any ideas like:

<?php if (isset) $_COOKIE[‘targ_lang’]; {

Rename this.new $_COOKIE['targ_lang'] to $_COOKIE[‘targ_lang2’];

}

?>

I could then read the cookies on the index.php with:

<?php if (isset) $_COOKIE[‘targ_lang’] and (isset) $_COOKIE [‘targ_lang2’] {

header('Location: http://www.xxx.com/a_page_displaying_both their_languages.php');

}

?>
That page would have a

Select your language:

<a href"http://www.xxx.com/Login/<?php echo $_COOKIE['targ_lang']; ?>.php"><?php echo $_COOKIE['targ_lang']; ?></a>

or:

<a href"http://www.xxx.com/Login/<?php echo $_COOKIE['targ_lang']; ?>.php"><?php echo $_COOKIE['targ_lang']; ?></a>

They could select their language and then go to the proper login page.

Bearing in mine my inexact syntax, does that make sense and does it look like it would work?

Or, back to my original question, is there a really obvious solution to the multiple user problem I'm overlooking? (as usual)

As always,

Thanks for your help.

Brian

This topic has been closed for replies.
Correct answer David_Powers

Instead of storing just the target language in the cookie, store the username and the target language. When somebody logs in, check their username, and get the appropriate target language.

2 replies

Inspiring
June 25, 2009

Okay, let me limit this to one question:

How do I prevent people who share a computer, but who don't log on or off, from overwriting each others's cookies when they register on my site.
I didn't understand David's idea of using the username as the name of the cookie. What does that look like?

Brian

David_Powers
David_PowersCorrect answer
Inspiring
June 25, 2009

Instead of storing just the target language in the cookie, store the username and the target language. When somebody logs in, check their username, and get the appropriate target language.

Inspiring
June 25, 2009

Hi David,

Okay, that part makes sense. But how do I name them to avoid being over-written?

Inspiring
June 25, 2009

How about using the username as the name of the cookie?


Can a cookie name be set dynamically like that?

So that I could have multiple users on a computer who don't log out?

<?php setcookie("first_name", French, time(0)+3600, "/", ".cinelingua.com");

?>

So first_name would be set from the registration page input field for First

Name?

That would be really cool. What does that look like?