cookies with php

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
humpy
Forum Newbie
Posts: 5
Joined: Sat May 29, 2004 9:27 pm

cookies with php

Post 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
User avatar
scorphus
Forum Regular
Posts: 589
Joined: Fri May 09, 2003 11:53 pm
Location: Belo Horizonte, Brazil
Contact:

Post 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.
User avatar
tim
DevNet Resident
Posts: 1165
Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio

Post by tim »

dont forget the isset() function

Code: Select all

<?php
if (isset($_COOKIE['logged])) {

// do something

} else {

// do something
}
?>
slimsam1
Forum Commoner
Posts: 49
Joined: Wed Aug 21, 2002 12:20 am

Post 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...
User avatar
tim
DevNet Resident
Posts: 1165
Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio

Post by tim »

no - but its a good habit and more professional

my opinion, do whatever, it'll still work.

heh :P
humpy
Forum Newbie
Posts: 5
Joined: Sat May 29, 2004 9:27 pm

Post by humpy »

i dont know php can you show me the whole code
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
humpy
Forum Newbie
Posts: 5
Joined: Sat May 29, 2004 9:27 pm

Post by humpy »

this doesn't help me any
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

Post 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.
slimsam1
Forum Commoner
Posts: 49
Joined: Wed Aug 21, 2002 12:20 am

Post 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...)
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

if isset() will return false, $_COOKIE['logged'] will fire a notice/warning saying undefined index.
slimsam1
Forum Commoner
Posts: 49
Joined: Wed Aug 21, 2002 12:20 am

Post by slimsam1 »

feyd wrote:if isset() will return false, $_COOKIE['logged'] will fire a notice/warning saying undefined index.
Good to know, thanks!
User avatar
tim
DevNet Resident
Posts: 1165
Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio

Post 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$ :x
Post Reply