Page 1 of 1
cookies with php
Posted: Sat May 29, 2004 9:27 pm
by humpy
okay when someone trys to download a file from my page i want to search for a certain cookie. if the cookie is not there i dont want them to download the file and i want to display a message. if the cookie is there i want them to be able to download the file.
so if someone could help me with this coding it would be greatly appreciated
Posted: Sun May 30, 2004 1:10 am
by scorphus
Take a look at the [php_man]setcookie()[/php_man] reference and the
Predefined Variables specially
$_COOKIE, play around, give it some try and then a couple more. Then if you still have trouble please come back here and we'll be very glad to help you.
Regards,
Scorphus.
Posted: Sun May 30, 2004 8:30 pm
by tim
dont forget the isset() function
Code: Select all
<?php
if (isset($_COOKIE['logged])) {
// do something
} else {
// do something
}
?>
Posted: Sun May 30, 2004 8:49 pm
by slimsam1
tim wrote:dont forget the isset() function
Code: Select all
<?php
if (isset($_COOKIE['logged])) {
// do something
} else {
// do something
}
?>
is there any reason to use isset when
Code: Select all
<?php
if ($_COOKIE['logged]) {
// do something
} else {
// do something
}
?>
works fine too?
Edit: Unless logged is set to FALSE or 0...
Posted: Sun May 30, 2004 9:03 pm
by tim
no - but its a good habit and more professional
my opinion, do whatever, it'll still work.
heh

Posted: Sun May 30, 2004 10:40 pm
by humpy
i dont know php can you show me the whole code
Posted: Sun May 30, 2004 11:20 pm
by feyd
using isset($_COOKIE['logged']) over $_COOKIE['logged'] should be done because a professional script should produce nearly zero errors, warnings, or notices in the logs.
Posted: Sun May 30, 2004 11:31 pm
by humpy
this doesn't help me any
Posted: Sun May 30, 2004 11:51 pm
by d3ad1ysp0rk
Learn php. We're not your slaves.
We teach here, we don't write scripts. If you want a full script, pay someone, or learn the language.
Posted: Mon May 31, 2004 12:56 am
by slimsam1
feyd wrote:using isset($_COOKIE['logged']) over $_COOKIE['logged'] should be done because a professional script should produce nearly zero errors, warnings, or notices in the logs.
What errors, notices, warnings does it place in the logs?
(I'm sincerely interested in this...)
Posted: Mon May 31, 2004 1:08 am
by feyd
if isset() will return false, $_COOKIE['logged'] will fire a notice/warning saying undefined index.
Posted: Mon May 31, 2004 1:47 am
by slimsam1
feyd wrote:if isset() will return false, $_COOKIE['logged'] will fire a notice/warning saying undefined index.
Good to know, thanks!
Posted: Mon May 31, 2004 11:16 am
by tim
lol thanks for backing me up feyd, error or not... its a more professional way to code and for a beginner, a nice way to start learning the proper way.
this doesn't help me any
you freaking rude slacker, go to php.net and read on isset() and setcookie()
lazy as$
