Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cookie name as variable 1

Status
Not open for further replies.

overyde

Programmer
Joined
May 27, 2003
Messages
226
Location
ZA
Hi,
Can I assign a variable as a cookie name?
i.e.

$_SESSION[cook_name] = cookie;

setcookie ('$_SESSION[cook_name]', 'yes');

if so, what is the correct way?

Reality is built on a foundation of dreams.
 
Why wouldn't you be able to do that?

Your example, however, is flawed.
Code:
# are you assigning a constant here?
$_SESSION[cook_name] = cookie;
# did you mean:
$_SESSION[cook_name] = 'cookie';

# this will not work:
setcookie ('$_SESSION[cook_name]', 'yes');
# you need to get rid of the single quotes.
setcookie ($_SESSION['cook_name'], 'yes');

This does not answer the question why it would be necessary to set a cookie besides using sessions. And if so, why wouldn't that cookie have a name that is set within a common configuration include that is part of all pages?
 
I'm doing a voting page that requires 1 vote per venue at a minimum time span of 24hrs.

So say, (and I know that they can disable cookies)Someone votes for 2 venues they visited. The cookie must carry the name of the venue with an expiry time of 24hrs so they can vote for the second venue the frequented.

Any other ways you can think of instead of this one?

Reality is built on a foundation of dreams.
 
Here's a suggestion:

1. Set a cookie to identify the voter.
2. Keep a table in a database that logs the votes over 24 hours and discards them after that.

As I'm writing this, I realize that this is just a database driven session system where the session TTL (time to live) is 24 hours.

You can easily set up that specific session system and just include it in the voting page scripts without influencing anything in the other sessions.

There's a FAQ faq434-2037 (it has some minor mistakes...) about implementing that.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top